Since the latter don't seem to work across different rooms, I assume variables are constant throughout the game...
Are variables like global switches?
RPG Maker MZ SupportSwitches stay in the state you set them during an event, so I'm not sure what you mean? Would love to help if you can tell me more!
To check the status of a switch, simply use a conditional branch in your event (I'm sure you know all this!)
Variables are different from switches, in that a switch can have two states: ON or OFF.
A variable can have one of any number of values, but can only store one at once. Like switches, you have to check against them for what you need.
For example:
You might use a switch called "Camp Password", which can be on or off.
You might have an event which checks whether that switch is ON before it allows you to pass into a certain area.
In another area, you might have an event which teaches you the correct password, and turns that switch ON when you run the event (all switches are OFF by default, and all variables have a value of 0).
A variable is a lot more fluid.
Lets say in the above example, that the password has been split up into ten parts, and you need all of them to get in. You could have ten different switches, which all have to be checked in embedded conditional branches, before you are let into the camp. Or, you could use a variable - let's call it "Password Letters" - and every time you learn part of the password, you increase the value of this variable by one.
Then you'd simply have one conditional branch which checks whether the value of the variable is equal to or greater than 10 - the number of pieces that password was split into.
In short, switches are meant to be used for things which have two states.
Variable are meant to be used for things which have multiple states, or for where you need a specific value.
A simple use of variables is for gold found in chests - On the chest event, you can set a variable to pick and random number between 50-100, and then to give the party the gold amount which equals that variable.
I hope all of that is of some help!
To check the status of a switch, simply use a conditional branch in your event (I'm sure you know all this!)
Variables are different from switches, in that a switch can have two states: ON or OFF.
A variable can have one of any number of values, but can only store one at once. Like switches, you have to check against them for what you need.
For example:
You might use a switch called "Camp Password", which can be on or off.
You might have an event which checks whether that switch is ON before it allows you to pass into a certain area.
In another area, you might have an event which teaches you the correct password, and turns that switch ON when you run the event (all switches are OFF by default, and all variables have a value of 0).
A variable is a lot more fluid.
Lets say in the above example, that the password has been split up into ten parts, and you need all of them to get in. You could have ten different switches, which all have to be checked in embedded conditional branches, before you are let into the camp. Or, you could use a variable - let's call it "Password Letters" - and every time you learn part of the password, you increase the value of this variable by one.
Then you'd simply have one conditional branch which checks whether the value of the variable is equal to or greater than 10 - the number of pieces that password was split into.
In short, switches are meant to be used for things which have two states.
Variable are meant to be used for things which have multiple states, or for where you need a specific value.
A simple use of variables is for gold found in chests - On the chest event, you can set a variable to pick and random number between 50-100, and then to give the party the gold amount which equals that variable.
I hope all of that is of some help!
Both are constant throughout the game. Switches just go on or off, while variables store a value in them.
I did use a variable in order to add by one every time something was activated, but I simply used the variable condition section of an event to check, instead of a branch (or maybe that's how it internally works...)
But switches didn't seem to work when the player got transferred to another map, so I assume they're not global... unless it's for some other reason it didn't work.
But switches didn't seem to work when the player got transferred to another map, so I assume they're not global... unless it's for some other reason it didn't work.
Switches do carry to map. Self switches though do not, as those are per event.
Switches stay the way you set them until you change them again.
If you used a switch and it changed without you telling it to, then you've either got a plugin that also changes it, you're changing it in an event and just forgot that it's happening, or you used a self switch.
If you need help with that, show us a screenshot of the event where you set the switch so we can see what you've done (and confirm what the switch number is, because sometimes it only shows the name you gave it and not the description).
If you used a switch and it changed without you telling it to, then you've either got a plugin that also changes it, you're changing it in an event and just forgot that it's happening, or you used a self switch.
If you need help with that, show us a screenshot of the event where you set the switch so we can see what you've done (and confirm what the switch number is, because sometimes it only shows the name you gave it and not the description).
It's possible that you're using a plugin which uses a certain switch by default, and forgot, then used that switch yourself.
Original thread: https://forums.rpgmakerweb.com/threads/are-variables-like-global-switches.139891/