Home > RGSS Script Reference > Game_Variables
Game_Variables
Inherits from: None
Description: This class holds the game variables and has methods for assigning and getting data from variables.
class Game_Variables
# ------------------------------------
def initialize
@data = []
end
# ------------------------------------
def [](variable_id)
if variable_id <= 5000 and @data[variable_id] != nil
return @data[variable_id]
else
return 0
end
end
# ------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
@data[variable_id] = value
end
end
end
|
Data: The array of game variables. Contains 5000 integer variables that can have a value between -99999999 and 99999999.
Initialize
Arguments: None
Local Variables: None
How it Works: Initializes the variable array to an empty array.
[]
Arguments:
Variable_ID: The array index of the variable value to return.
Local Variables: None
How it Works: This method returns the current value associated with the variable ID passed to it. If the variable ID is 5000 or less and isn't nil, the current value of the variable is returned. Otherwise, the method returns 0 because a value hasn't been assigned to the variable yet.
[]=
Arguments:
Variable_ID: The array index of the variable to set.
Value: An integer representing the value to assign to that variable.
Local Variables: None
How it Works: This method sets the current value associated with the variable ID passed to it to the value passed to the method. If the variable ID is 5000 or less, the variable is set to that value. Otherwise, the method does nothing because the variable ID isn't valid.
|
|