New account registration is temporarily disabled.

MCBICK'S PROFILE

Search

Filter

[RM2K3] C++ Data Structures

Is there a rule of thumb when to use an array, vector, list, etc?

[RM2K3] C++ Data Structures

@DNKpp
Isn't it bad practice to use vectors instead of arrays though?

[RM2K3] C++ Data Structures

I found the issue now. I checked what I was doing, and my pointer is in fact off which resulted in the size value to not be used. I have been coding on and off, so I had to refresh myself on my old code and I did not look carefully enough at the pointers.

Thanks for the feedback everyone.

On another note, should I be using a vector for storing condition Ids or an array? The reason I am using a vector now is because I can easily sort through the elements. This is necessary because I reorder the elements based on the priority in the database manager, which lets me control which condition is displayed in the status/battle menu.



[RM2K3] C++ Data Structures

author=Cherry
#include <algorithm>

// ...

// Note this is an std::vector<int>::iterator and not an int
std::vector<int>::iterator pos = std::find(conditions.begin(), conditions.end(), conditionId);
if (pos != conditions.end()) // == conditions.end() means the element was not found
    conditions.erase(pos);
This is much cleaner than what I wrote, but I still have the same issue. I still can't reduce the size of my vectors when using erase and clear. Every time I try to use something like:
int numConditions = conditions.size()
I always get the maximum number of elements that were used in that vector, even after erasing or clearing the vector.

New Example
std::vector<int> conditions;
int currentSize = conditions.size(); //Value of 0
conditions.push_back (50);
conditions.push_back (51);
currentSize = conditions.size(); //New value of 2
conditions.clear();
currentSize = conditions.size(); //This should be a value of 0, but the value is 2

[RM2K3] C++ Data Structures

author=AubreyTheBard
int i = std::find(conditions.begin(), conditions.end(), conditionId);
This will not compile which is why I wrote it the other way. Also I added the resize line because erase did not properly resize.

I checked my code again and you're right int i is wrong. The correct line should have been this, but this still doesn't fix my resize issue. I will fix my example to reflect this too.

int i = std::distance(conditions, std::find(conditions, conditions + conditions.size, conditionId));

The example is not my actual code, just a demonstration of what I am trying to do. I don't have anything coded yet, until I can solve the issue. I figured out the issue, but I'm not sure how to fix it. The issue is that I can increase my vector size, but I can't decrease it, no matter which function I use. I think the memory for the vector needs to be reallocated for it to properly resize, but I am not sure how I would achieve this. I am having the same issue with the clear function as well.

[RM2K3] C++ Data Structures

Is there an easy way to update the size of a Vector? I am using a vector to store condition IDs of the actor, but when I erase an element and resize the vector, each time the condition is removed or expired, that vector's size does not update and I get an incorrect value for the number of elements in the vector.

Example:
std::vector<int> conditions;
int conditionId;
bool removeCondition;
//...
if(removeCondition == true)
{
removeCondition = false;
int oldSize = conditions.size();
int i = std::distance(conditions, std::find(conditions, conditions + conditions.size(), conditionId));
conditions.erase (i);
int newSize = conditions.size(); //Why does this still equal the old size?
...
}

Should I just be using a different structure to track conditions? If so, what would be a better method?

[RM2K3] DynRPG RPG::Skill::conditionFlag Help!

I made a plugin that takes any skill used and replaces the skill with another. Unfortunately if I try to change skill A to skill B and skill A inflicts a condition, but skill B doesn't then I must change the condition flag, but this does not work in practice. What happens is the condition flag does change, but the skill will not inflict the condition. I have tried doing the reverse as well, where the skill removes a condition, but that also doesn't work unless both skills have the same condition flag in the database, prior to me changing any skills via script.

[RM2K3] DynRPG RPG::Skill::conditionFlag Help!

I am trying to change the condition flag of a skill when a battler "first try" their action during the onDoBattlerAction callback, but it does not do anything. I checked and the skill does get changed, but the affect of changing inflict to remove does not reflect in battle. Is this not possible to do? Changing any of the other RPG::Skill variables during the onDoBattleAction callback will work as intended, but the conditionFlag switch does not appear to have any affect in battle, despite actually being changed.

I would post my code, but it isn't as simple as a few lines in one location, so it would be confusing to post a bunch of snippets of code. I have tried a simpler code to make sure it isn't my coding. Even this won't work:

bool onDoBattlerAction(RPG::Battler* battler, bool firstTry)
{
    if(firstTry == true))
    {
        RPG::skills[1]->conditionFlag = false;

Again the conditionFlag is accurately changed, but it does not reflect in battle.

[RM2K3] DynRPG Compiling Error

I don't have any now as I have rewritten my code to work around that issue, but if I run into that issue again I will remember to save it. It typically occurs with Battler stats in general when I try to retrieve them to calculate damage before damage occurs, so I can insert my own damage algorithm. The code is usually executed when the Battler's action meets a certain condition, but before they display their action animation, which all occurs in the onBattlerAction callback.

[RM2K3] DynRPG Compiling Error

@Kazesui
I took a quick look at it and there seems to be a lot to learn from, thanks!

@Cherry
Do you happen to know why battler variables change during battle in rm2k3 when they shouldn't? During callbacks like onBattleStatusDrawn, if I manipulate battler objects during certain conditions I get the wrong values. For example I tried using a battler's condition ID to trigger an event, but when my code checked the ID it would return a 7 digit value.