[RM2K3] [DYNRPG] GETTING NAMES OF VARIABLES AND SWITCHES

Posts

Pages: 1
Has anybody managed to use the name functions for variables and switches in DynRPG v0.30+? I've gotten code to compile with them, but when it runs, I get memory access violations. Here's what I think it should look like:

message << "RPG::variables.name( 1 ).s_str() == " << RPG::variables.name( 1 ).s_str() << "\n";
message << "RPG::Switches::name( 1 ).s_str() == " << RPG::Switches::name( 1 ).s_str() << "\n";

It's a little weird, but the name function for the Variables class is a regular object function, while for the Switches class it's a static function, hence the different syntax. The bizarre thing is, I could almost swear that second one with the switches actually did work once after I figured out I needed to use s_str(), but on subsequent tries I got access violations again.

For reference:

Variables class
Switches class

EDIT: And just to eliminate a potential stumbling block, yes, this code is called after the game is up and running and there are variable and switch values populated, confirmed by checking RPG::system->variables.size and RPG::system->switches.size.
Use:
RPG::switches.name(i).s_str()
RPG::variables.name(i).s_str()

Edited - was wrong before. It's definitely supposed to be that, but whether or not it still works is a different story.
Okay, just for documentation in case anybody else ever runs across this problem: it turns out part of the problem was the debug code I was using. I have a template for doing dialog box popups that looks something like this:

// DEBUG

std::stringstream message;
message << "value I want to check == " << value << "\n";
MessageBox(
NULL, // We don't need a window handle
message.str().c_str(), // Text
"Debug", // Title
MB_OK // Flags
);
// /DEBUG


Trying to use RPG::variables.name(i) after using this debug snippet would cause a memory access violation error. Bizarrely, the part that was messing it up was apparently the mere declaration of a std::stringstream variable; even if I commented out the rest of the snippet and didn't use the variable, it would still cause a crash when it got to the RPG::variables.name(i) call. After eliminating the debug snippet, I was able to use RPG::variables.name(i).

Switches is a different story. Even without the std::stringstream variable being declared, it always seems to cause a memory access violation. Also, just to note, the syntax for calling the switch name function PepsiOtaku describes above --
RPG::switches.name(i).s_str()
-- is only valid if you go into the DynRPG source code Switches.h and remove the keyword 'static' from the declaration of the name function. As it is, the code should be this --
RPG::Switches::name(i).s_str()
-- although either way it causes a memory access violation in my experience.
Pages: 1