Variable use question

I'm not sure how to really ask this. I would guess it would be "Can a variable be used in more than one event?"

For example, if I make an NPC that has a variable set to random 1-3 and gave it the name "Random talk" for random talk.

But I made another event with another random talking NPC and listed the same variable but changed it to 1-5 for random messages.

How does that work? Will the NPC with 5 supposed random messages will only be able to display 3? Will it change my event I had listed for 3?

Apologies, I'm not always sure how to explain things. Just ask me to clarify. I've kinda been wondering about this.
Can't you use two variables?

Or, perhaps, set variable value to random number between 1 and 15. Event 1 uses values between 1-5, 6-10 and 11-15; and Event 2 uses 1-3, 4-6, 7-9, 10-12 and 13-15. Much more work than use two variables.
Well, if each NPC activation sets the variable to a number in the event's range before displaying the appropriate text, it shouldn't be a problem in any case, since the potential 4 or 5 from NPC 2 would be reset by speaking to NPC 1 again anyway.

Variables and Switches are, by the design of the engine, made so they can be used by any number of Events. 🙂
all the variables are stored in the same place (simply put), but are used only by one process at a time.
despite the engine seeming to process things in parallel, it only just processes one instruction at a time, every time...... only, many thousands of instructions per unit of time.

whatever variables you store up, if you overwrite them through another process, they'll always hold the last value introduced.
they'll only give you errors if you call up the same variable on different processes, without accounting for any out-of-range values.

if you set variable 001 to hold a random number, and it settles down on "2", it'll always be "2" unless you redefine it some time later, and it will still be valid within parameters within that process.
once you exit the process, if you come back, you'll have to validate the data again, just in case.

the variable management was the first thing I checked out when I got around VX.
I realized it wasn't flexible enough for me, so I ditched the database editor and went directly to the source code.
there, I can manage as many variables as I want.
the advantage of using the engine's variables, is that they are global, and can be accessed by the whole game.
the disadvantage, is that you'll run out of definitions for variables if you don't design your data structure carefully, and you have to guarantee that one variable definition (or more than one) is locked to *one* specific process for the duration of that process.
I have a few reusable variables like Count, Index, Calculation etc. The trick is to set the variable right before you use it and only in situations where you know you won't need that value later on.
When you 'set' the variable, it will overwrite whatever is stored in that variable with the new number.

Your two events wouldn't be in any way conflict with each other despite using the same variable, since both events 'set' a random number.

I actually use two designated variables that are temporary only, I use these mostly for calculations and store the result in another variable. But any number of events make use of these two variables to calculate some things. It's really useful, because I can keep using them over and over again since I'm always resetting the value anyway.

Variables are reeeallly useful like that 🙂

Original thread: https://forums.rpgmakerweb.com/threads/variable-use-question.79642/