MZ What are variables and how do I use them?

I'm making a system using the "Number Input" command, where you enter a four-digit code received on a physical card (this is one of my sandbox games that I'm making for myself to play on YouTube). Each code unlocks exclusive items and characters to use, and I'm even designing blind packs of these cards just so Helen Henny can open them on camera.

There's just one issue. The "Number Input" command needs a variable, and I am absolutely clueless on how they work. I checked the help file and I couldn't find anything coherent that my Autistic brain could clearly understand (yes, I have Autism), so here I am.

Can someone please explain what variables are, how they work, and how to use them? I'm trying to create this feature without having to use a plugin, so any help is much appreciated. Thanks in advance.
You can think of a variable as a sort of box. It can hold pretty much anything. Numbers, letters, sentences, arrays, you name it.

You can use a variable whenever a simple switch won't quite cut it. In your example, the number input will save the number that the player put in into that box (the variable) and keep it there until you put something else in.

That way you can then for example make a conditional branch where you check if this number inside that variable is bigger than or smaller than or whatever else you want to check that number for.

So with your code system, you could check "if Variable "Code input" = 1234 unlock this character, else if variable "Code Input" = 1235 unlock this other character" and so on.

Hope that makes it more approachable.
If you're interested, I once wrote up a quick tutorial for someone walking them through basic use of variables and switches. Take a look if you think it'll help.



This was made for someone using FES, but it should do for MV and MZ too.
This was so helpful! I'm saving this information for future reference... I may even get to use variables regularly in the future if I get good with it.
I'm going to play around with it a little. Thank you!
This was so helpful! I'm saving this information for future reference... I may even get to use variables regularly in the future if I get good with it.
I'm going to play around with it a little. Thank you!
You're welcome. Honestly, I should redo it with images one of these days. Would be a good upgrade.
That would be a great upgrade. I'm leaving this open for now in case anyone else has something to add.
The simplest example of a variable I can think of would be having the player collect apples. Naturally you don't want to turn on a different switch for every apple, right? So you use a variable. Whenever the palyer picks up and apple, you do "Variable Apple +1". And the npc who you need to give the apples to will then have a conditional branch "If Variable Apple = 10 say "That's enough apples!" else "Sorry, I'll need more of dem apples."
By the way, in case it makes you feel better, when I first used RM, variables went over my head. I just couldn't get it until a day or two later when I woke up and it just clicked. Was a weird experience, but I laugh about it now.
By the way, in case it makes you feel better, when I first used RM, variables went over my head. I just couldn't get it until a day or two later when I woke up and it just clicked. Was a weird experience, but I laugh about it now.
Heh... well, I've been using RM for years and I still didn't understand until now. Guess all I really needed to do was ask! 😉 Here's to hoping I can use this new info to my advantage.
Heh... well, I've been using RM for years and I still didn't understand until now. Guess all I really needed to do was ask! 😉 Here's to hoping I can use this new info to my advantage.
If you need any help finding the MZ equivalent of the various commands in that tutorial or just have general questions, feel free to tag me. While I'm sure others will still chime in, as @SGHarlekin did, I'll be happy to help if I'm available.
Thank you so much.
I suggest you play the Variables Guide - a game made to teach what variables are and how to use them. After that you can even download an VXA trial to open that game and see how the events for it were made.

It was made with VXAce decades ago, but since Variables are basically mathematics, nothing there has ever changed.

I'd love to, but VXAce doesn't work on my Mac (though I do have it. I bought it for my PC before it broke and left me with just a MacBook Pro). Would have been awesome though.

Original thread: https://forums.rpgmakerweb.com/threads/what-are-variables-and-how-do-i-use-them.181047/