Is there a way to use less variables or does it not matter that much?

I am completely new to RPG Maker and I am curious about variables.

If I want to set an event that needs a character, I could assign him a variable and call it when I need an event that only runs with him but, I quickly realized that thousands of variables would be used for things like this.

For example, I want to set a quest that needs a certain actor, I would need to use one variable for this to activate but, if the same event would have different ocasions depending on the actor used, I would use 10 more variables for example. And if I have a hundred events like this throughout the whole game, this would be 1.000 variables because I think I can't reuse them since this would reactivate an already completed event.

Now for my question, is there a way to "save" variables? And do variables affect the game's perfomance when I set a lot of them?

(This may be a dumb question, I'm completely new to programming so, I apologize if this is something that I could easily find the answer or if it's a dumb question.)
You have self switches for each event, thats 4 "variables".

You have normal variables which you can plan ahead to reset and reuse if the player wont visit certain maps again and you have switches, for global changes to multiple events, using these 3 you can have a lot more combinations than you think.

Use self switches first and foremost, then go for switches.

For the record i avoid using switches as much as possible,i recycle variables a lot and use self switches as much as i can.

An example of a variable recycling: o have a boss encounter that needs 4 kills, each enemy kill adds 1 to the variable, then when the variable reaches 4 an autorun event flips self switch A, resets the variable to 0, and runs the event cutscene as normal on the next page with self switch A as condition, the boss variable is free to be used again.
When I made my 1st game, I used around 170-200 variables. (I forgot the exact number).
At the time, I was also new to RPG Maker, and was confusing their usage a lot. So I suspect a lot of my first set of variables I ever used probably could've been used better, I often used them in place of switches, hah!

As BK-tdm already said, you have Self-Switches, Switches, and Variables, all of which give you several possibilities. You do not need to use variables for every single thing.


Since we don't really know much about your game as a whole, I can give you general advice:

1) Self-Switches are key for events where something is effected only for that specific event it's being used on, and nothing else. (Dialogue text for an object, a shopkeeper, etc.)

2) Switches are great for global events as BK-tdm has already said. You'd be surprised how many "variants" can really be boiled down to an ON or OFF switch. (The player does something that changes another event, or even a set of events elsewhere. A key unlocking a door, etc.)

3) Variables are greater than Switches, but also more complicated. They provide you the utility for variance such as storing information for ID's and location-based things (actor ID's, Map X/Map Y coordinates, item counts), as well as randomness. (Setting a variable to pick from a range you create).

Now for my question, is there a way to "save" variables? And do variables affect the game's perfomance when I set a lot of them?
The answer is that Variable data is stored and saved at ALL times unless you have an event that controls it to do something else.
What this means is that Variable #0001...will always be equal to...let's say you make it 1 for some reason. Then Variable #0001 will always be equal to 1 unless you event some kind of change otherwise.

This is only consistent per save, and will be reset to previous data if the game is closed before the next save. (If I play a game, and go to some event that controls Variable #0002 = 3, then I suddenly quit the game and restart, Variable#0002 will be reset back to whatever it was before it became 3.)

Also, don't worry about using too many variables.
I highly doubt you will use anything close to 1000 of them.
And even if you did, it shouldn't effect performance that much unless you're running a bunch of parallaxes/autoruns at the exact same time in-game (which is very unlikely).


At the end of the day, it is up to you to decide which tool is best for what you want to happen. But knowing your tools well can benefit in the long run.

Do not be afraid to ask questions for looking dumb. You come here to learn and seek help, and we will help you as much as we can with whatever you provide us in screenshots or text. (Screenshots are always super helpful).
The previous advice is great. I also use and reuse a ton of Variables.

One suggestion I would make is to search for RPG Maker MZ and then the keywords Variable and Switches. You will find a lot of great tutorials that will explain a lot. YouTube has tons of very helpful tutorials.

Good luck and ask as many questions as you need.
All of the above advice is good - also, consider whether you actually need variables. For example:

For example, I want to set a quest that needs a certain actor, I would need to use one variable for this to activate but
I don't understand why this would use a variable. On the event that could trigger giving the quest, I'd do a Conditional Branch -> Tab 2 -> Actor is in party

What would the purpose of a variable there be?

if the same event would have different ocasions depending on the actor used, I would use 10 more variables for example.
Same thing - why would this use any variables, much less 10? Just use conditional branches to see who's in the party.

And if there were a reason for a variable, why wouldn't you just use one variable and determine which actors/combination thereof is in the party by the value of that variable?

The answer is that Variable data is stored and saved at ALL times unless you have an event that controls it to do something else.
Judging from the context of the post, I think the OP was saying "save" as in is there any way to "conserve" variables 😉

But there's a bit of language translation going on, so I might be wrong.
All of the above advice is good - also, consider whether you actually need variables. For example:


I don't understand why this would use a variable. On the event that could trigger giving the quest, I'd do a Conditional Branch -> Tab 2 -> Actor is in party

What would the purpose of a variable there be?


Same thing - why would this use any variables, much less 10? Just use conditional branches to see who's in the party.

And if there were a reason for a variable, why wouldn't you just use one variable and determine which actors/combination thereof is in the party by the value of that variable?


Judging from the context of the post, I think the OP was saying "save" as in is there any way to "conserve" variables 😉

But there's a bit of language translation going on, so I might be wrong.
The purpose I was thinking is to call it whenever there is script involved like changing the spritesheet for an specific attack and etc. But, I will use the conditional branches since it seems to solve the issue and scripts are too advanced for me to worry about them for now.

I never thought about giving each combination and party member a number, that's an excellent idea. Thank you!

And english is not my main language so, I may have misused the word. You are correct, with "save" I meant conserve.
You have self switches for each event, thats 4 "variables".

You have normal variables which you can plan ahead to reset and reuse if the player wont visit certain maps again and you have switches, for global changes to multiple events, using these 3 you can have a lot more combinations than you think.

Use self switches first and foremost, then go for switches.

For the record i avoid using switches as much as possible,i recycle variables a lot and use self switches as much as i can.

An example of a variable recycling: o have a boss encounter that needs 4 kills, each enemy kill adds 1 to the variable, then when the variable reaches 4 an autorun event flips self switch A, resets the variable to 0, and runs the event cutscene as normal on the next page with self switch A as condition, the boss variable is free to be used again.
I have tested this recycling and it worked. Thank you for the advice on switches too, I was not very sure why would I use them when there are already self-switches and variables. I understood it now.
And english is not my main language so, I may have misused the word. You are correct, with "save" I meant conserve.
You didn't misuse it, you were just misunderstood.
And do variables affect the game's perfomance when I set a lot of them?
It doesn't.

If you use too many variables. The one that is having a problem is yourself as a dev and how you manage it.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-use-less-variables-or-does-it-not-matter-that-much.153481/