The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Heretic86 on June 06, 2011, 12:57:38 AM

Title: How do I call a Game Variable in a Script?
Post by: Heretic86 on June 06, 2011, 12:57:38 AM
The short version.  Im screwing around with a script where I have to set some of the variables by the script.
player.variable = 1 as an Event Script.  How do I set a Game Variable to that value?  I tried player.variable = $game_variables
Title: Re: How do I call a Game Variable in a Script?
Post by: ForeverZero on June 06, 2011, 02:33:28 AM
$game_variables[VARIABLE_ID] = VALUE
Title: Re: How do I call a Game Variable in a Script?
Post by: Heretic86 on June 06, 2011, 07:28:40 AM
Quote from: ForeverZero on June 06, 2011, 02:33:28 AM
$game_variables[VARIABLE_ID] = VALUE

Thats what I thought.  I just want to temporarily override what I am calling a user defined variable...

message.text_speed = $game_variables[99]

I doubt this has anything to do with it, but the script window keeps putting the [99] on a new line.  When I try to run it, I get:

QuoteScript 'Multiple Message Windows SDK' line 1176: NoMethodError occured.
Undefined Method `-' for #<Game_Variables: 0xSomeCrap @data=[]>

/scratches_head
Title: Re: How do I call a Game Variable in a Script?
Post by: LoganF on June 06, 2011, 07:35:42 AM
Common problem with using the Script... call under Advanced.

Each line is separately processed as its own line. Try something like:


var = $game_variables[99]
message.text_speed = var


Shortening the line length by creating variables with smaller names is pretty much the quick and easy (probably the only) way to deal with that issue.

Title: Re: How do I call a Game Variable in a Script?
Post by: Heretic86 on June 06, 2011, 09:21:21 AM
So if the script doesn't all fit on the same line, it doesn't compile the variable or class names the same way?  Like its inserting a \r or \n character between $var
Title: Re: How do I call a Game Variable in a Script?
Post by: LoganF on June 06, 2011, 11:54:02 AM
Only for the Event based Script called (under the Advanced section of the Event Commands list).

If you mean in the actual scripts database section, there shouldn't be any issue regarding how long each line is, as long as each line is its own statement (this isn't completely true, but for simplicity's sake it's a good thing to follow).
Title: Re: How do I call a Game Variable in a Script?
Post by: Heretic86 on June 07, 2011, 12:06:39 AM
Quote from: LoganForrests on June 06, 2011, 11:54:02 AM
Only for the Event based Script called (under the Advanced section of the Event Commands list).

If you mean in the actual scripts database section, there shouldn't be any issue regarding how long each line is, as long as each line is its own statement (this isn't completely true, but for simplicity's sake it's a good thing to follow).

It was an Event Based Script...
Title: Re: How do I call a Game Variable in a Script?
Post by: brewmeister on June 10, 2011, 08:50:58 PM
You can also escape the line-feed character that the editor puts in for you...

message.text_speed = \
$game_variables[99]

just make sure there are no spaces after the backslash