Main Menu
  • Welcome to The RPG Maker Resource Kit.

How do I call a Game Variable in a Script?

Started by Heretic86, June 06, 2011, 12:57:38 AM

0 Members and 1 Guest are viewing this topic.

Heretic86

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
  • where X is the ID of the Game Variable.  \v[99] also only works for displaying that as text as far as I can tell...
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

ForeverZero


Heretic86

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
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

LoganF

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.

(Why do I always feel like it's the end of the world and I'm the last man standing?)

Heretic86

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
  • and $var\n
  • are not the same?

    Thats one Goofy bug but thanks for letting me know!
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

LoganF

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).
(Why do I always feel like it's the end of the world and I'm the last man standing?)

Heretic86

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...
Heretic's Vehicles XP (Boat and Magic Carpet)

Heretic's Collection XP Ver 2.3 - Updated to include Dynamic Lighting, Moving Platforms, Vehicles, and much much more!

brewmeister

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