New account registration is temporarily disabled.

MCBICK'S PROFILE

Search

Filter

[RM2K3] DynRPG Compiling Error

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.

[RM2K3] DynRPG Compiling Error

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.

[RM2K3] DynRPG Compiling Error

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?

[RM2K3] DynRPG Compiling Error

So basically for manipulating Rm2k3 objects I should, and need to, use std map, but for integer arrays I should use vectors? I thought vectors could store other values such as with std::vector<Rpg::Image> myImage, but I guess not.

When I get a compiling error with strings it always refers to them as chars or const chars despite only using static std string and std string variables, so I thought that maybe they were the same.

For global variables I must use static or const outside the main() and all functions correct? That is what I have been doing anyways. I've also used static variables inside functions, so it only initiates the value once and can be changed within the function later if need be.

For arrays why does something like int N = RPG::monsters.size(), not work? I am trying to find a way to easily keep track of the size of certain rm2k3 arrays without using a loop every time I need their array size. As it is now I have created a function just to count array sizes as I am tired of constantly using loops every time I need the array size.

[RM2K3] DynRPG Compiling Error

@Kazesui
Could you explain the differences of std::map and vector? From what I understand they can both be used for the same thing? So when would I use one over the other?

For instance what is the difference or limitation between these two types of arrays, if any?
std::map<int, RPG::Image*> images
//and
std::vector<RPG::Image*> images

Also what is the difference between these arrays?
const char* myText[3] = {A, B, C};
//and
static std::string myText[3] = {A, B, C};

[RM2K3] DynRPG Compiling Error

author=Kazesui
There are ways to simulate key presses with C++ code, but it's very hacky and I would not really recommend this as a solution. Apart from that I'm also not sure how to force the change.
I looked into it and you're not kidding. I will try experimenting more with navLevel a bit more and if I can't figure it out then I will just do away with all of the windows and battle data and create my own system from scratch using custom windows or possibley just altering the existing windows if I can figure out why every time I change the window's image size it just becomes a scrambled mess of pixels.

Also thanks for all the input with both DynRPG and C++, it was very helpful.

Does anyone know why this occurs to my window?

I adjusted the window's width and it seems to not redraw the frame correctly now.

void getWindowPos()
{
if(RPG::battleData->winCommand->width != 96)
{
RPG::battleData->winCommand->width = 96;
RPG::battleData->winCommand->image->width = 96;
RPG::battleData->winCommand->redraw();
}
Also does anyone know what the Window::refresh() function is supposed to do?

EDIT: I figured out why the window becomes a scrambled mess of pixels when changing the size. It is necessary to use the RPG::Image::init() function instead of changing the image's width of the window. I have only been successful doing this with the imageText though. For some reason when changing the frame size, the game continues to redraw the same sized window despite using the init() function to alter it's width and height. It is also necessary to use the Window::refresh() function any time you alter the window's dimensions, so the game can readjust it's internal pointers for navigating windows and redrawing them correctly.

[RM2K3] DynRPG Compiling Error

[RM2K3] DynRPG Compiling Error

author=Kazesui
If you don't need direct access to the various pointers, there are also other alternatives you could use, like std::list or std::vector.
std::vector resembles a normal array which you can call with the square bracket operator, but dynamically increases it's size as needed (assuming you use the right methods).
If you're looking at learning a little bit of C++, having a quick look at all three of these could be a good start as they are very common, and generally useful. If you simply want to draw all pictures you've made, it could be easier to just put them all in a std::vector and then iterate over all the elements in the array.
This is immensely useful to know, thanks. This gives me a better understand of these data structures and will make coding in the future more efficient. I'll continue to learn more about these 3 structures and better utilize them.

author=Kazesui
std::map<int, RPG::Window> myWindow;
void createWindow()
{
myWindow = RPG::Window()
myWindow.create(64, 64, 120, 96, false)
}
I tried this too, but it gives the same error. I think the issue is the destructor in the class, but I am not familiar with how destructors work, so I could be wrong. I may just be better off creating my own window function as nothing I have tried works, not to mention I would have more customization options if I make my own.

I experimented with the RPG::battleData::navLevel and I have discovered some things. If I set it to 0 first, I will then be allowed to change it to whatever value I want, but this ends up doing nothing if I set it to RPG::BNAV_IN_COMMAND_WINDOW, so useless. Also this is the exact error I receive, "Access violation in module "RPG_RT.exe" in with address 004BFF9E and offset 00000034 of type Read occured". If I understand correctly the address is to RPG::battleData and the offset is RPG::battleData->navLevel, but I'm not sure why it is a Read type violation.

Is there a way to force input? I could do that instead, but I don't see a way to force input in DynRPG.

[RM2K3] DynRPG Compiling Error

So if I am to understand correctly using the map operator is in fact allocating the proper memory for me? I just want to make sure. I have changed my code to this for images.
//Plugin
void onFrame(RPG::Scene scene)
{
    if(scene == RPG::SCENE_MAP) //I change this to different scenes for testing purposes, but will change it to a pointer.
    {
        if(getImage) //This is a global bool
        {
            CBS::createImage(0, 120, 120, 16, 24);
        }
    }
}
//header
std::map<int, RPG::Image*> myImage;
std::map<int, RPG::Image*> myText;
void createImage(int img, int x, int y, int stringX, int stringY)
    {
        std::string pathName = "Picture\\Field.png"; //I will probably change this to a global string or parameter later.
        if(!myImage[img])
        {
            myImage[img] = RPG::Image::create();
            myImage[img]->loadFromFile(pathName);
            myImage[img]->useMaskColor = true;
            myText[img+1] = RPG::Image::create(myImage[img]->width, myImage[img]->height);
            myText[img+1]->useMaskColor = true;
            myText[img+1]->drawString(stringX, stringY, pathName, 8);
            myText[img+1]->setSystemPalette();
        }
        RPG::screen->canvas->draw(x, y, myImage[img]);
        RPG::screen->canvas->draw(x, y, myText[img+1]);
    }
I didn't know there was a code tag, thanks for pointing it out. So is this code good now? Right now this is just for testing purposes, so I will probably redesign it, but is the process of how I am handling classes and objects okay now? Also I am unsure exactly how the map operator works. How big of an array could I use with it and how does the compiler know how big of an array to allocate memory for if I am creating new objects during run time?

If I create new RPG::class objects will I have to destroy them with the onExit function or will they terminate themselves? I have run into an issue before where closing the game did not end the program on my system and I had to manually end it via task manager, but that could have been bad code as I was experimenting at the time on how image functions work and wrote it differently then.

author=Kazesui
You might use the same variable name, but the code don't consider that to be the same object. You might have saved the address of that memory block in some other variable somewhere else in the code and want to reuse that variable name for a new pointer, which is what's happening it the code you outlined.
How can that be? I thought variables are an address in memory, so if I use the same variable it is using the same memory? Otherwise how would you manipulate memory? How can I ensure I am using the same memory then?

author=Kazesui
Is it actually being destroyed or just not drawn? Not necessarily the same thing. You need to draw an image every frame, because if you don't the next frame is drawn on top of the old image and you won't see it anymore. This is why the text plugin also uses the onDrawPicture callback, since this something which is drawn for every frame (if the picture exists), but still allows for some graphics chosen by the developer to be put on top of the text (which is why I did not go for onFrame or onScreen myself).

What I would recommend, is to create all the images necessary in onComment callback at the start of a battle, and then to draw the images created in onFrame (without the use of RPG::Image::create in this callback). You use Destroy when the image is not used anymore or when the battle is over at which point you'll have to stop drawing as well (onFrame will keep drawing whatever it's told to draw whether you're in a battle or not, so you'll need a way to discern when you're in battle).
This is very useful info thanks. I was going to experiment with different functions to figure out the order in which it draws to canvas. This will save me time and frustration. I am currently using this for onComment function, so I can manipulate images in different RPG::scenes.
bool onComment(const char* text,
               const RPG::ParsedCommentData* 	parsedData,
               RPG::EventScriptLine* 	nextScriptLine,
               RPG::EventScriptData* 	scriptData,
               int 	eventId,
               int 	pageId,
               int 	lineId,
               int* 	nextLineId)
{
    static std::string cmd;
    std::string textString;

    cmd = parsedData->command;

    //Call Image through comment.
    if(0 == cmd.compare("cbs_image"))
    {
        getImage = !getImage;
        return false;
    }
    return true;
}

By any chance do you know how the Window class/functions operate? I keep running into a memory read error. Also any idea why this line of code "RPG::battleData->navLevel = RPG::BNAV_IN_COMMAND_WINDOW;" results in an access violation model type read error? I execute it when the hero battler is selected in the winParty window, their atb bar is full, and when "RPG::battleData->navLevel == RPG::BNAV_IN_PARTY_WINDOW" is true. I am trying to open the winCommand window without having to select a battler and press the decision key.

std::map<int, RPG::Window> myWindow;
void createWindow()
    {
        myWindow[0].create(64, 64, 120, 96, false);
    }
This function results in a memory read error, "A violation in C08BC35D occured at C08BC35D with Read".

[RM2K3] DynRPG Compiling Error

@Kazesui
So I actually considered that, but I thought the game was deleting them. I use a global variable for my image objects, but when I create an object via a function, for example onComment, my image is destroyed after that function is executed, so I don't even see it being created. I haven't noticed any high memory usage at all, but I will check for them. I thought it was frowned on to use the new operator as the compiler is supposed to allocate memory for you? This is basically how I have created images before and currently.

Before
//Plugin Name
#include <DynRPG/DynRPG.h>
#include <CBS.h>
#include <vector>
#include <iostream>
#include <string>
#include <iterator>
std::map<int, RPG::Image*> myImages;

bool onComment(parameters...)
{
static std::string cmd;
cmd = parsedData->command;
if(0 == cmd.compare("cbs_image"))
{
std::string pathName = "Picture\\Monster1.png";
myImages(0) = RPG::Image::create();
myImages(0)->loadFromFile(pathName);
myImages(0)->useMaskColor = true;
RPG::screen->canvas->draw(132, 108, myImages(0));
return false;
}
return true;
}

Current
//Plugin Name
#include <DynRPG/DynRPG.h>
#include <CBS.h>
#include <vector>
#include <iostream>
#include <string>
#include <iterator>
std::map<int, RPG::Image*> myImages;
static bool getImage;

onFrame(parameters...)
{
if(getImages)
{
std::string pathName = "Picture\\Monster1.png";
//Should I add a destroy function here to stop the memory leak?
//Should I add an If(myImages(0)) for the following three lines of code?
myImages(0) = RPG::Image::create();
myImages(0)->loadFromFile(pathName);
myImages(0)->useMaskColor = true;
RPG::screen->canvas->draw(132, 108, myImages(0));
}
}


This is just made for testing purposes right now. I thought in c++ objects created are destroyed after the function is terminated, unless you return an object? From what I am to understand I am generating an infinite amount of Image objects? How can that be though, if I am creating the same object? And how is it that my image is constantly being destroyed over and over? From what I can tell the game is destroying it every frame which is why I have it draw every frame, otherwise if I only initiate it once through the onFrame function then my image literally shows for one frame, I've tracked it to be sure.

I'm actually studying up more about c++ memory allocation now since it seems to be a major issue I have run into for creating my turn based battle plugin. I'm currently trying to utilize the Window class, with minor success because of memory write issues. Also can't get the battle navigation to not crash with a DynRPG 1114 error. So the info about stacks and heap is quite helpful. I'll try to look online for more info because I think you're right that my code is leaking memory. The problem is I don't know at what point to destroy my images, as I am not sure why they keep disappearing in game.

EDIT So I added an if statement to check if there was an image object before creating it and it solved my memory issue, so thanks for pointing it out.