I was trying figure out how to add 1 to a variable every 30 steps the characters make, but I don’t want to have to make it check for 30 steps, then check for 60 steps, and then 90 steps and so on. What would be the best way to make that happen?
Add Variable Per Step Count
RPG Maker MV SupportCan you reset the variable counting the steps every time?
is it something that needs constant updating? if it isnt, then whenever you need the variable, use the control variables event command to get the current step count and then use a second one to perform the "mod" operation with a constant of 30
The steps set the variable and the internal step counter doesn’t go down. So after 30, when resetting to 0, the next step would set it to 31.
Ah, right, I see. I forgot there was a way to get the step count.
I don’t completely understand. It’s like my brain almost understood what you meant then stopped. Lol
i misunderstood what you wanted a bit actually. it can be simplified, but the idea is the same. divide instead of using modulo and itll get you a number that goes up by 1 for every 30 steps the player took
to explain, the modulo operation is the fifth basic mathematical operation, one that is rarely used in regular life (where addition, substraction, multiplication and division, the other four, are used constantly).
it basically tells the remains after a division, so 31 mod 30 would be 1, 65 mod 30 would be 5, 81 % 30 would be 21 (% is how modulo is shortened in formulae.
so basically you test the step counter, and whenever step % 30 is the same as zero, you add to the variable.
However that only works as long as you can guarantee the parallel process checks at least once per 30 steps, and is prevented from checking twice.
the first limits how many waits you can give the parallel - but still should allow a wait(10) to reduce lag.
the second would need an old-step variable to compare before updating, to not add anything if the difference is too low.
EDIT: @Robro33 your description of modulo is wrong
it basically tells the remains after a division, so 31 mod 30 would be 1, 65 mod 30 would be 5, 81 % 30 would be 21 (% is how modulo is shortened in formulae.
so basically you test the step counter, and whenever step % 30 is the same as zero, you add to the variable.
However that only works as long as you can guarantee the parallel process checks at least once per 30 steps, and is prevented from checking twice.
the first limits how many waits you can give the parallel - but still should allow a wait(10) to reduce lag.
the second would need an old-step variable to compare before updating, to not add anything if the difference is too low.
EDIT: @Robro33 your description of modulo is wrong
use 2 variables.
use 1 variable to get game data steps
than something like:
if: variable 1 > 30
variable 2 += 1
variable 1 = 0
end
just make this a parallel in a common event and it does the rest.
use 1 variable to get game data steps
than something like:
if: variable 1 > 30
variable 2 += 1
variable 1 = 0
end
just make this a parallel in a common event and it does the rest.
As soon as you've taken 30 steps in the game, every time you run that event it will always add another 1 to your second variable.
I know as the OP want to check every 30, than 60, than 90 to add +1 to a variable.
so every 31th step = +1 to variable 2 unless I miss understood his way?
+1 * 30 gives you the correct amount of steps that is saved as well or am I wrong here?
Yes, but that's not what your event is doing.
Your event will say
Variable 1 has 30 steps -> variable 2 +1
Next time you check it,
Variable 1 has 34 steps -> variable 2 +1
Next time
Variable 1 has 36 steps -> variable 2 +1
Now variable 2 has a value of 3 but you've only walked 36 steps.
You need to do what Robro already explained in post #7, divide the number of steps by 30 to see how many increments of 30 the character has walked. Then there's no need to have variable 2.
I reset variable 1 to 0, but Robro's aswer works too, as there are some ways to pull this off.
probably better as well depending the situation I think.
I don't understand what you're getting at. You reset it to 0, then at the top you set it to steps, which will always be the number of steps the character has taken.
If you set it to 0 and don't set it to steps...then it will always be 0 and variable 2 never increases no matter how many steps you take.
The issue is if variable 1 is the game steps, game steps never get reset. So resetting it to 0 does nothing. If you counted the steps yourself THEN it would work to do what you said. But since you call game data, it will do this:
When you hit 30 steps.
Var1 = is set to 30, var2 = 1, var1 = 0. But that is meaningless, as next step you set var1 = 31 as you are setting it to the game steps (which is never reset. Var1 was set to 0, but since it does = game steps instead it will overwrite it with that), so var2 = 2.
When you hit 30 steps.
Var1 = is set to 30, var2 = 1, var1 = 0. But that is meaningless, as next step you set var1 = 31 as you are setting it to the game steps (which is never reset. Var1 was set to 0, but since it does = game steps instead it will overwrite it with that), so var2 = 2.
Thank you so much everyone! Sorry. I ended up having a long day. So I just divide by 30 is what I understand. @Robro33
Okay. So I thought about this specifically. If I divide by 30 and I’m at 60 steps, then wouldn’t that add 2 to the variable?
nope. if you do both parts of what i mentioned, itd set the value to 2, not add to it
once you set a variable to be equal to the steps taken and then divide that same variable by 30, youre overwriting the value to the result of that division every time. theres no addition involved, and previous iterations of the process have no impact on that value is currently
To clarify a few more things:
there are several ways to get what you want, and we told you three different ways above - but unfortunately those ways got mixed up as everyone assumed something without writing it down.
done correctly on their own, each way would have worked, but the mixup of the incomplete descriptions caused confusion even among us and resulted in several posts going wrong.
If you can't sort the methods out on your own, please post a screenshot of your current event and we can specifically tell you how to correct that.
because you need to chose one method from the three mentioned above before anyone can help you with that.
there are several ways to get what you want, and we told you three different ways above - but unfortunately those ways got mixed up as everyone assumed something without writing it down.
done correctly on their own, each way would have worked, but the mixup of the incomplete descriptions caused confusion even among us and resulted in several posts going wrong.
If you can't sort the methods out on your own, please post a screenshot of your current event and we can specifically tell you how to correct that.
because you need to chose one method from the three mentioned above before anyone can help you with that.
Old: I appreciate all your help everyone. I’m still currently working on it and will update this reply once I got it.
Edit: I got it. I am just going to reset the steps using this
since I'm not using steps for anything else.
Thank you so much everyone for all your help!
Edit: I got it. I am just going to reset the steps using this
Code:
$gameParty._steps = 0;
Thank you so much everyone for all your help!
Original thread: https://forums.rpgmakerweb.com/threads/add-variable-per-step-count.172607/