[RM2K3] DYNRPG COMPILING ERROR

Posts

Seems I wasn't using vectors quite right before then, but I get the gist of it now. I'll have to reconsider my choices of vector and map uses.

If I don't use static or const for global variables won't they reinitiate their value every time rm2k3 is run? This is fine for const variables because they're always the same, but for non-const this could return incorrect values in the code after the first time opening it. For example, if I needed a global to keep its value between the opening and closing of rm2k3 application, wouldn't using non-static variables reinitiate their values every time I opened the rm2k3 application?
Yes the global variable would receive the initial value set whenever you load the plugin, which would be when you open the application. I would be quite surprised if adding the static keyword would change that. If you want to have variables which persist, you'll probably have to look into storing the data into files instead.
Is there a difference between non-static and static global variables? From my understanding, static is only initiated once, but if it's a global variable that is declared at the beginning of my header or plugin(cpp), outside all functions and structures, then wouldn't it only ever be declared once anyways, making it the same as a static variable?

Example:
//PluginName
#include DynRPG/DynRPG.h
static int myVar = 99;
//... the rest of the plugin.

//vs

//PluginName
#include DyNRPG/DynRPG.h
int myVar = 99;
//... the rest of the plugin.
In the example, would both variables only be declared once, and only at the start of the plugin? If so then is there any reason to use a static global variable? Sorry for the noob question, I just want to clarify my understanding on exactly how these variables work as it would make a big difference in how I declare them in my code.
author=McBick
Is there a difference between non-static and static global variables? From my understanding, static is only initiated once, but if it's a global variable that is declared at the beginning of my header or plugin(cpp), outside all functions and structures, then wouldn't it only ever be declared once anyways, making it the same as a static variable?

Example:
//PluginName
#include DynRPG/DynRPG.h
static int myVar = 99;
//... the rest of the plugin.

//vs

//PluginName
#include DyNRPG/DynRPG.h
int myVar = 99;
//... the rest of the plugin.

In the example, would both variables only be declared once, and only at the start of the plugin? If so then is there any reason to use a static global variable? Sorry for the noob question, I just want to clarify my understanding on exactly how these variables work as it would make a big difference in how I declare them in my code.


As long as you have all of your code in a single file, there is no real difference between having a global variable and a global static variable. The difference comes into effect when you start splitting your code across multiple .cpp files. The difference being that you can access the same global variable in another .cpp file with the help of the keyword "extern", but the same won't work for a static variable.

Note this is not quite the same for header files, as a declared variable there, will be accessible to all files which includes them.

Bottom line, as long as you work on a single file there will be no real difference whether you declare them as static or not. It makes a bigger difference when used in classes and functions. It's pretty much up to you whether you want to use it or not.
Alright, just wanted to make sure. I initially thought any variables declared outside functions, classes, and structures would be declared repeatedly, each time a function was executed if said variable didn't have the static attribute, but that is not the case. Thanks for the clarification.
Does anyone know what is expected for this line of code?

RPG::WindowMenuSkill->winInfo->y = 120;
//Error: Expected unqualified-id before '->winInfo->y = 120' token

This is the code I am pointing to in the DynRPG Window.h;

class WindowMenuSkill : public Window {
		public:
			int heroId; //!< Database ID of the hero selected
			Window *winInfo; //!< The sub-window for the skill description
			Window *winHeroInfo; //!< The sub-window for the selected hero information
				int _unknown_84;
			DList<int> *skillSubsets; //!< Zero-based Array of skill subsets. Unsure about this though...
			bool isSkillSubset; //!< Is the selected skill a subset?
			//Window *winHeroMp; // ????

			void refreshSkills();
	};
I am guessing because WindowMenuSkill has the properties of class Window I have to point to the object in a different way than what I am currently using, but I have tried pointing to it several different ways, all of which results in the same error.
author=McBick
Does anyone know what is expected for this line of code?

RPG::WindowMenuSkill->winInfo->y = 120;
//Error: Expected unqualified-id before '->winInfo->y = 120' token

This is the code I am pointing to in the DynRPG Window.h;

class WindowMenuSkill : public Window {
		public:
			int heroId; //!< Database ID of the hero selected
			Window *winInfo; //!< The sub-window for the skill description
			Window *winHeroInfo; //!< The sub-window for the selected hero information
				int _unknown_84;
			DList<int> *skillSubsets; //!< Zero-based Array of skill subsets. Unsure about this though...
			bool isSkillSubset; //!< Is the selected skill a subset?
			//Window *winHeroMp; // ????

			void refreshSkills();
	};
I am guessing because WindowMenuSkill has the properties of class Window I have to point to the object in a different way than what I am currently using, but I have tried pointing to it several different ways, all of which results in the same error.

RPG::WindowMenuSkill is a class. A class is kind of like an advanced variable type, with multiple fields and methods belonging to it.
std::string is also a class, and you need to instantiate an object of the type std::string before you can use it. An exception to this is static methods and variables. This is why RPG::Image::create(); works, but RPG::Image->free() would not work. Still, remember that in DynRPG, you should normally not instantiated your own objects from the classes.

Instead vou need to consult this page:
http://www.rewking.com/dynrpg/group__game__objects.html
to see what instantiated objects you have to work with.

In your case, what you're trying to do should probably be something along the line of
RPG::battleData->winSkill->winInfo->y = 120;

Can't guarantee that it won't cause issues though, as I don't know if rm2k3 will like you messing with it's variables.
Also worth noting here is that "winSkill" is defined as a "RPG::Window" class, not a RPG::WindowMenuSkill class, meaning you should not really have access to the member variables specific to RPG::WindowMenuSkill.
In good C++ fashion, you would normally be able to get this access by
skill_subset_0 = dynamic_cast<RPG::WindowMenuSkill*>(RPG::battleData->winSkill)->skillSubsets[0];
No idea if this would actually work here though, as these classes are not very conventional. (I expect this not to work, but this would be the general idea of how you would normally get access to those member variables).

related note: WindowMenuSkill is another class which "inherits" from the class Window. What this means is that WindowMenuSkill expands upon the class Window by adding extra member variables and methods, sometimes overwriting old methods from the original class with a new one. If you have an instance of WindowMenuSkill which has been instantiated as Window, and you only need members and methods from Window, there should be no problem. If you need access to the specifics of WindowMenuSkill, you need to start thinking along the paths described above.
I understand about instantiated rm2k3 objects, so I stay away from that. I am not sure what you mean by having an instance of WindowMenuSkill which has been instantiated as Window. As far as I can tell the objects in that class are static and can only be called, not instanced.

I tried using the dynamic cast operation, but get the error "not a polymorphic source". Ill continue to try using that type of method to see if I can get it to work.
author=McBick
I understand about instantiated rm2k3 objects, so I stay away from that. I am not sure what you mean by having an instance of WindowMenuSkill which has been instantiated as Window. As far as I can tell the objects in that class are static and can only be called, not instanced.

I tried using the dynamic cast operation, but get the error "not a polymorphic source". Ill continue to try using that type of method to see if I can get it to work.


Time for some terminology again.
An object is an instance of a class. Let's take string as an example again
std::string some_text;  // The object here is "some_text" which is an instance of the class "std::string"


If you look up the documentation of RPG::Window and RPG::WindowMenuSkill, you'll see that the keyword "static" does not appear anywhere. This means that nothing in these classes are static and cannot be called upon or used without an instance of that class.

RPG::WindowMenuSkill is a class, and not an object. You need to find an instance of the class to be able to use it (because of how DynRPG works).
This is why
RPG::battleData->winCommand->width = 96;  // winCommand here is not as static object, but rather an instance of the object. By using this, you are using an instance of the underlying class.
RPG::WindowMenuSkill->winInfo->y = 120;  // This does not work since this is not static and not an instance of WindowMenuSkill


The thing about DynRPG is that you are not allowed to create new instances of the classes mentioned, but you will have to use instances already made of these classes.
A quick way to discern these two are if the first letter following RPG:: is lower or uppercase. If it is lowercase, this means that this is an instance already made (by mapping it specifically to the existing memory in RPG Maker, which is the only way to create an instance for almost all DynRPG classes), and can be manipulated upon. If the first letter is uppercase, it means it's a class, and only static members (which are defined as such in the documentation) can be used, like RPG::Image::create(), which is labelled as a static public member in the documentation.
As you can see
RPG::battleData is an instance of RPG::BattleData, while RPG::WindowMenuSkill is simply a class definition (and the class has no static members, so you can't access anything in it without a pre-existing instance.

Again, you need to consult
http://www.rewking.com/dynrpg/group__game__objects.html
as to what instances already exist, since you can't create new instances yourself generally.

As for the dynamic cast operation, I figured that it probably wouldn't work (since DynRPG classes are anything but normal). My next best guess is that you'll have to use reinterpret cast and find the exact memory location of the window, and possibly toss in some dereference and address operators akin to what is done in the header files. I can't really say what would work here without experimentation as this is not the kind of code I'm particularly experienced with myself. Again, this should only be important if you actually need access to the specific variables members of RPG::WindowMenuSkill specifically. If all you want to do is mess with the y member, which is part of RPG::Window, you will not need this, and if you don't get access to it, is for different reasons, which has nothing to do with being able to cast the instance as the correct class (casting something, generally means to change the underlying type of the variable / object, and only works for cases where there is support for this. This will not help you directly, because all conventional wisdom will not work for DynRPG, but conceptually, you can learn more about this by reading about "polymorphism").
So that's why some classes are referred to with a lower case starting letter! This makes so much sense now!

When I mention instantiated objects, I meant specifically the ones the coder refers to and not the one that is declared in Dyn RPG, but now I have another question regarding this. In the header, the BattleData class has no static members. It is the same in the other header for the WindowMenuSkill class. Aside from the lower case letter needed for battleData the class object winSkill and winInfo are identical, though the latter inherits the Window class properties. So how and why are these two members so different to work with? Am I misunderstanding something here? There is a static reinterpret cast for BattleData, but does that change the class members to static?

I am trying to edit existing properties in rm2k3, such as menu windows. For most of the Window objects that rm2k3 creates I have been able to figure out how to manipulate them, albeit painstakingly, but there are a few Window objects like winInfo that I have issues manipulating. I will continue to read up on polymorphism and continue to experiment with winInfo.

author=McBick
So that's why some classes are referred to with a lower case starting letter! This makes so much sense now!

When I mention instantiated objects, I meant specifically the ones the coder refers to and not the one that is declared in Dyn RPG, but now I have another question regarding this. In the header, the BattleData class has no static members. It is the same in the other header for the WindowMenuSkill class. Aside from the lower case letter needed for battleData the class object winSkill and winInfo are identical, though the latter inherits the Window class properties. So how and why are these two members so different to work with? Am I misunderstanding something here? There is a static reinterpret cast for BattleData, but does that change the class members to static?


It is not a requirement for the letter to be lowercase, but rather it's following a common naming convention. BattleData is the class and battleData is an instance of BattleData. On line 136 of BattleData.h you'll find
static RPG::BattleData *&battleData = (**reinterpret_cast<RPG::BattleData ***>(0x4CDD38));

Now, I'm sure this line can be rather confusing as this is some rather advance stuff where you'd possibly run into some issues trying to google it. You'll be forgiven if you're not able to follow what I'm about to describe. Essentially, the class "RPG::BattleData" has been written in such a way, that the member variables fit perfectly on top of pre-existing memory as defined by the original RPG Maker software. "reinterpret_cast" here, dictates that you should take the address (0x4CDD38) and treat it as if it is an object of the class "RPG::BattleData".

In a sense, the original software has already defined the class RPG::BattleData, but this is normally not accessible because it's given as an already compiled binary, so this data has to be extracted from the memory through memory mapping (which is what is done here). This is why you shouldn't make another instance of RPG::BattleData either, as it's only existing once in the memory anyway, and it has already been mapped into the object RPG::battleData.

Again, RPG::battleData is an object, not a class. Because it is an object of the class, you can access all it's members. The fact that it's declared as static is of little interest here, as does not mean that anything inside the class has been converted to static.
I imagine you might be a little confused because you don't understand how C++ classes work, because you're learning from DynRPG, where most classes only have a single object (the global one accessible from DynRPG itself), but usually, classes are there to be treated as variable types which you can create as many as you like of, which is where the difference of a static member of a class kicks in, versus a normal member variable of the class, which belongs to the specific object itself.

All of this aside, I didn't read properly when I was skimming over the documentation, so I didn't see that "WindowMenuSkill" actually refers to the skill sub-window from the "menu". I thought it was the battle skill menu because I recall you've been working with that one so far, but that doesn't seem to be the case, so no wonder things seemed a bit weird.
The proper way of accessing it should be
RPG::menu->winSkills->winInfo->y = 120;

probably while checking to make sure with an if statement that the skill menu is currently the active window.

This does render your question of "how winskill and wininfo" are different a bit moot, but it has to do with polymorphism. It is a bit involved to explain this, and it will probably just confuse you more than it will help you, so I'll leave this be for now.
Oh, when I made that remark about lower case letters I meant with DynRPG classes only. I never knew the reason why so many classes in DynRPG started with lower case letters until now.

I think I understand what you mean about the classes overlapping with the memory in rm2k3 software. I actually altered some memory values myself when I was working with keyboard inputs, to try to force key inputs. Now that you mention how I interact with classes I suppose it is true, I have only been working with one instance of a class at a time, usually DynRPG, so I have forgotten the utilization of multiple instances. Up until now I have mostly used structs instead of classes as I am uncertain why I would use a class over a struct. My main cpp file contains all the structs while I have a header with all my non-DynRPG functions and so far this has proven sufficient. I am only doing simple stuff though. I imagine classes would be more useful with more complex coding.

author=Kazesui
RPG::menu->winSkills->winInfo->y = 120;
I should have checked SceneMenu page or the header file more carefully. I can't believe I missed that.

I have been reading up on polymorphism and it has given me ideas on how to further manipulate rm2k3 objects. I started with only wanting to create a custom battle system, but the more I learn about c++ and DynRPG the more I realize how much control I have over the rm2k3 software, so I am currently working to revamp it to something akin to Dragon Quest.
Does anyone know how to make this conversion work?
int Actor;
RPG::Battler* battler; //I am using the DynRPG callback onBattlerDrawn for this example.
Actor = &battler; [code c++][/code]
//This line of code doesn't work either, similar error message:
//Actor = battler; 
//error: invalid conversion "RPG::Battler**" to "int"
I am trying to convert the value of battler(the current acting Hero/Monster) to an int variable, Actor. I don't want to store the address of battler, but the value that exists in the address of battler. Does that make sense?

Also I am aware I can get the battler value through something like this:
RPG::battleData->currentHero;
This isn't what I am looking for though. I am trying to learn how to convert the value stored in a pointer's address to an int variable.
Battler is not an int. There is no obvious way to turn a collection of variables and methods into a single int value, so this doesn't work (Unless you extend the classes with operator overloading to allow for that, but please don't try to do this).

Are you sure that it's the battler your want and not the id? i.e.
actor = battler->id;  // "Actor" should be "actor" since it's not a class definition
@Kazesui
I see now that was a bad example. I'm trying to learn a method that converts the value stored in a pointer's location to an int.
//Example
int a;
Namespace::class *Ptr;
a = &Ptr->variable;
//This results in an invalid conversion of pointer to int

Does that make sense?
Conventionally, what you do when you want to get the value within a pointer, you want to do something like this:

int a = 8;  // declares an integer variable and sets it value to 8
int* b = &a;  // declares a pointer to an integer variable and points it to the address of variable a
int c = *b; // declares an integer variable and sets its value to the value stored at the address of pointer b


The * is called a dereference operator, and is used to the get the value at the end of an address.

Keep in mind however that
actor = battler->id;  // this
actor = (*battler).id; // is the same as this


the -> operator is an dereference and access member operator in the same go, which is why you get the value straight when using the arrows, while with a struct you'd make, you'd might just use foo.member to access the value.
so when you do battler->id, you're already getting the value stored at the end of the address.
So I think I understand what you're saying, but I keep running into conversion errors. What is the difference between these two declarations?
int* b = &a;
//and
a* b;

Also what is the difference between these two declarations?
int* b = &a;
//and
int* b = a;
//What would c equal if a = 10 in this example, for both declarations of b?
c = b;

I am guessing the value of c for both declarations would be 8, but then what is the difference of using one or the other?
int* b = &a;  // this tells the compiler to create a variable of type int, and make it a pointer, and then it tells it to take the address of variable 'a'
a* b; // This should fail to compile, since you're trying to declare a variable 'b' of type 'a' and make it a pointer, but 'a' but a is a variable, not a type or class

int* b = &a;  // Again, tells the pointer b to take address of a
int* b = a;  // Should not compile, since you're trying to set a pointer variable to an integer value. 'b' expects an address, not a value
c = b;  // This depends on what 'c' is. if c is an int, then this should also fail, because c expects a value, not an address


It's an important distinction whether a variable contains an address or a value, and that's where most of the issues arise from.
use & to get the address of a variable
use * to get what value is stored at an address (when applied to a declared variable)
use * to turn a variable declaration into a pointer type variable
For the first example I was supposed to show:
int* b;
And for the second example I missed an operator and should be this:
int* b = &a;
int* b = *a;
int c = b;

Also is something like this the same declaration:
RPG::Battler* battler;
//Is the following line the same declaration as the above line?
int* battler = &RPG::Battler;

I've been reading up on pointers, dereferencing, and referencing and I feel like I understand it and then I practice it, but I still some how keep getting errors. I don't think this is supposed to be confusing at all, but I keep confusing myself when applying these operators.
author=McBick
And for the second example I missed an operator and should be this:
int* b = &a;
int* b = *a;
int c = b;

The difference there is that &a gives the address of variable 'a', while *a gives the value stored within the address of 'a'. If 'a' does not contain a valid address, doing *a will fail.

Some more examples to illustrate the difference between & and *
int a = 8;
int b = *(&a);  // this set b to 8
int c = &(*a);  // this will fail since it tries to dereference a, which is not an address
int* d = &a;
int* e = &(*d); // this will give the address of a
int f = *(&(*d)); // this should set f to 8
int g = *d;  // this is should also set g to 8

author=McBick
Also is something like this the same declaration:
RPG::Battler* battler;
//Is the following line the same declaration as the above line?
int* battler = &RPG::Battler;

You can't do that for multiple reasons:
1. RPG::Battler is a class definition, not a variable. You cannot take the address of a class definition
2. RPG::Battler is not an int, so trying to store it as an int pointer won't work. The underlying address might be stored in an unsigned 32 or 64 bit integer, but the compiler still expects the pointer type to be correct, such that derefererncing would still make sense.
int* actor = battler;  // this should fail
int hp = actor->hp;  // this would make no sense, since an int does not have any member hp
3. battler as given by the callback is already a pointer. Trying to get the address of a pointer gives you the address to the pointer itself, meaning it should be stored in a double pointer variable, i.e. of the type RPG::Battler**

Now, if you're really bent on converting it to something else, what you could do is
int* actor = reinterpret_cast<int*>(battler);
int actor_value = *actor;
The value of actor_value should now be an integer, but what value you'll get depends on what is stored in the first 4 bytes of the relevant RPG::Battler object instance. It's less intuitive than using the corresponding member variable.

Does this it make sense to do this? Not really, unless you want to work on the pointer address itself (for memory mapping purposes). If that is not what you're trying to do, you should not be doing this.