Variable Help
Learning JavascriptThe script box is build like a "sandbox" programming - closing a scriptbox deletes everything assoziated with it. So the next script box has no access to older variables, no matter what they are.
You can only store data in variables that had been defined outside the script command (by a plugin, or in the game variables)
You can only store data in variables that had been defined outside the script command (by a plugin, or in the game variables)
What would be the correct way to do this then? How do I associate a game variable with a string? How do I then call said game variable using the $gameMessage function?
You could set one of MV's variables like this (MV itself will only let you store numbers in them, but in a script you are free to do otherwise):
$gameVariables.setValue(1, "text");This will store the string "text" in variable #1.In your message, you can then use \V[1] to retrieve that value.
$gameVariables.setValue(1, "text");This will store the string "text" in variable #1.In your message, you can then use \V[1] to retrieve that value.
But what if one wanted to reference that variable in another script command instead for the purposes of conditional branches? What would the code for that look like?
That game variable are the ones contained in the editor, so think of them as something of a global scope. @Chronic Heart
This means
$gameVariables.setValue(1, "text");
Sets the game variable at id 1 in the editor to some string, which you can reference anywhere -- even in another script command for example.
This means
$gameVariables.setValue(1, "text");
Sets the game variable at id 1 in the editor to some string, which you can reference anywhere -- even in another script command for example.
Yeah, I figured that it would be in the global scope. I was just wondering what referencing a particular variable would look like in a script command. Maybe I'm just missing the obvious, but it seems to me that this line of code is a function for setting a value, not to check it. So how would I write an "if" statement based off of a variable? Would it look like: if ($gameVariables[0] == "text");? Or would it look like something else?
if($gameVariable.value(1) == "text")
It would look something like that. That would refer to the gameVariable at ID 1. @Chronic Heart
Rpgmaker tends to not use the zero index.
It would look something like that. That would refer to the gameVariable at ID 1. @Chronic Heart
Rpgmaker tends to not use the zero index.
Original thread: https://forums.rpgmakerweb.com/threads/variable-help.49378/

