[RMVXAce] Init variables on game load

I was looking at a couple variable tutorials and I notice there is a set variable command, but I didn't see any way to set variables on game load or maybe even map load? Let's say I don't want my variable to start at 0 but some other number how can I have it set once when the game loads?

Also, is there a way to save that information between runs or is that done automatically already for us? I have the lite version atm so would be interested if there is a script and non script way for those of these questions.

Thank you much!
I'm sure there's a way to do this script-wise, but if you want to start with certain switches on and certain variables at a value, simply have a parallel process run on the starting map, and you set these yourself. Then use a self switch (or erase event if you're never returning to that map again) to turn the event off.


What do you mean to save the information between runs? Anything you change to your project, and save, you will always have to start a new file to see and have the changes work correctly (so don't use an old save file if you have changed something to the project).
well, if you mean that you want a variable to preserve it's values between different playthroughs, then you would need something like the Persistent Data script...
So what I'm finding interesting is the order of events being ran. I run a parallel process event  that sets a variable called "tree" to 10. I then have an event on a tree tile that has 2 pages. The 1st page takes a player touch and reduced the "tree" variable by 1. The 2nd page has a condition of when the "tree" variable is 0 to basically disable the tree (not let the player gather anymore wood from it). However it would seem that 2nd page condition is hit before the variable gets set to 10 because it starts out disabled.

I could put a self switch on page 2 and set it in page 1 to prevent this, but the player can "chop" the tree multiple times so I'd need to toggle back and forth between pages.

Nevermind I got it. I put a conditional check on page 1 that says if the "tree" var is 10 then set self switch A and page 2 has self switch 2 in it's conditions. I have to think a little differently with all the event coding than I'm used too 🙂

@adiktuzmiko, Thanks, that's what I was talking about.
The event page with the highest number, whose conditions are met, will always run first and ignore all other event pages. If you have its condition set to a variable with 0 and above], it will always be met and will always ignore the previous event page. When it comes to event pages and variables, you'll have to work your way up. Start with the lowest number for the lowest event pages, and work up to a higher number on higher event pages so everything works chronologically.


So instead of setting the variable at 10, and subtracting 1 from the tree each time it's chopped, do the opposite. Start at 0, and add 1 every time it's chopped. Then when it's at 10, make another event page based on that condition and make the tree vanish or something.
I had that originally. The way I have now works but clearly is an extra step. The reason I was looking to change was because I would show some text after each chop saying this tree has x number of wood left. Since I was starting from 0 instead of 10, I needed a way to take (10 - variable) in the show text dialog but couldn't figure it out so I switched to this method. Is there a way to do some math in the show text dialog instead of it taking the literal of what I'm typing?
you have to make the math in a control variable command, but you can get the value of a variable displayed in the text by using \V[#] (with the variable number instead of #)


Hower the mouse over the text input window of show text and wait a few seconds to see a list of all text codes.
Well if you want to show the text, do as Andar said (type in \v[X] where X is the number of the variable).


And if you want to count down instead of up, go back to your tree event. The second event page, its condition should be set to the variable you're using, and to 1 (not 10) and above. This will be the event page that lets the player chop down the tree, as well as show a text window that says how many times there's left to chop. The first event page should have no condition, this should be the event page you use for when the player has chopped all 10 times.


You just have to get a bit creative with event pages 🙂
I do count up but I put a self switch (which I feel should be named local instead of self 🙂 ) to switch to the 2nd page when tree count = 0. For my brain I feel like pages should be executed from lowest to highest since that's sort of how you create them. 🙂 Some things seem like they are backwards to me. Start from 0 and count up instead of counting down, higher pages executed first. It'll just take me a little to get the hang of it, but I'm getting there 🙂

Thanks all!
I do count up but I put a self switch (which I feel should be named local instead of self 🙂 ) to switch to the 2nd page when tree count = 0. For my brain I feel like pages should be executed from lowest to highest since that's sort of how you create them. 🙂 Some things seem like they are backwards to me. Start from 0 and count up instead of counting down, higher pages executed first. It'll just take me a little to get the hang of it, but I'm getting there 🙂
Your main problem was in a different part - but probably you didn't realise that.

There is NO condition "Var = number" on any event page.

The condition you find on the event pages is "Variable X is number OR ABOVE".

Which means that your original setup was to trigger the second page on every value of the variable that was zero or higher - which is why that page was always active, because all values from 0 to 10 triggered the condition.
Yeah, after I set the var >= condition on the 2nd page it was a combination of both the 2nd page being executed first and that condition being met that was making it tirgger. That's why I put a self switch A on the 2nd page then. So it wouldn't trigger until the first page event if statement set self switch A when the tree var >= 10. Reversing my logic of counting up instead of down wouldn't require the self switch but then making the show text show the correct number would require me to subtract my max wood value (10) from the tree variable. Either way it's working now so all good. Thanks.
You are doing your event wrong. Again, I suggest you read some tutorials on how event pages work, and how variables work. I did already suggest that, and if you had read some, you wouldn't have made the mistake of putting 1 in the condition on the first page, and 0 in the condition on the second. You also don't need the self switch if you are using variables.


Show us your event (take screenshots of the event window, including the WHOLE event window, not just the commands), one for each page. You really are making this MUCH harder than it needs to be. In fact, even if you're using variables instead of self switches, you only need TWO pages on your event - unless you're changing the image with each chop.


Page 1 will have the tree image, no conditions, and the event command will add 1 to the variable.


Page 2 will have no tree image, and the condition will be Variable is X or more, where X is the number of times you want to chop the tree before it disappears.


This means you will NOT have to set your variable to 10 at the beginning of the game - it can start at 0, which is the default.
I had it working both ways. The only thing I didn't figure out when counting up was how to display how many were remaining.  With counting down I just showed the variable. Players will expect to see how many are left, so with counting up I would need to take the total value (say 10) and subtract that by the tree variable. Someone mentioned a control variable command but it doesn't look like the result can be sent to Show Text. Instead it would have to be stored into another variable and then I'd use that variable in Show Text.

var remaining = 10 - countingUpVar

(actually when I look at control variable command it seems to only let me have 1 value on the right side so without a script not sure if I could even do the above formula)

Maybe there is another way to get the remaining value without another variable that isn't obvious to me, but if there isn't then counting up uses 2 vars and a control variable command and counting down uses 1 var with an init and self switch. So I took the less variables route. Not that variables are bad in anyway, but the more trees I have the more variables and I just didn't want to clutter up the variables if I didn't have too I guess. If there is a way to Show Text the remaining count without another variable I'll switch to that for sure. I haven't found anything specifically on this though.
You would have to set variable 2 to 10, then do a second control variables to subtract variable 1 from it. I didn't realize you were actually showing how many there were left.
Just piping in - have you tried out the Variables Guide? It explains a lot about event pages as well.
Thanks Celianna. I only have the lite version right now. When I tried to open the project up with the lite version it says something about file format error.
even without opening the game, you can learn a lot by playing it.
I think this should accomplish what you want using a script:

module DefaultVar #Set the variables to be changedVariables = [5]endclass Game_Variablesalias initialize_defaultvars initializedef initialize(*a,&bl) initialize_defaultvars(*a,&bl) #Set variables to value (default 5) DefaultVar::Variables.each do |id| @data[id] = 5 endendendTo change the variables you're setting, just edit the number inside the Variables = [x] line (more than one is possible by putting commas between them), and to change the value they get set to (default 5), change the number at the end of the 10th line.
if you cannot open it, it's because it uses the full version Ace's proj exe... so just create a new project in Lite, go to it's folder, copy the proj file and paste it into the other project... you might wanna back up the Ace project file before doing this though... though some parts might not work because of the limitations of Lite

Original thread: https://forums.rpgmakerweb.com/threads/rmvxace-init-variables-on-game-load.19173/