Variable Help

Seleroan

Villager
Member
Joined
Oct 30, 2015
Messages
18
Reaction score
5
First Language
English
I am trying to set up a variable so that it contains a string.  Later, I want to be able to reference that variable.

I've uploaded a bit of code that works just fine and then a second bit of code that doesn't work.

Why does the game forget about the variable I just set up?

Invalid.png

Valid.png
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,365
Reaction score
7,675
First Language
German
Primarily Uses
RMMV
The 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)
 

Seleroan

Villager
Member
Joined
Oct 30, 2015
Messages
18
Reaction score
5
First Language
English
The 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)
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?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 

Chronic Heart

Warper
Member
Joined
Nov 12, 2015
Messages
3
Reaction score
0
First Language
English
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.
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?
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
794
First Language
English
Primarily Uses
RMMV
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.
 

Chronic Heart

Warper
Member
Joined
Nov 12, 2015
Messages
3
Reaction score
0
First Language
English
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.


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? 
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
794
First Language
English
Primarily Uses
RMMV
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.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,062
Members
137,575
Latest member
akekaphol101
Top