Source: Game_Variables.js

Game_Variables.js

//-----------------------------------------------------------------------------
// Game_Variables
//
// The game object class for variables.
/**
 * The game object class for variables.
 *
 * @class
 */
function Game_Variables() {
    this.initialize(...arguments);
}

/**
 * Initializes the variables
 */
Game_Variables.prototype.initialize = function() {
    this.clear();
};

/**
 * Clears all variables
 */
Game_Variables.prototype.clear = function() {
    this._data = [];
};

/**
 * Get the variable value for the given variable id
 *
 * @param {number} variableId - The variable id
 * @return {number} The value stored in the variable
 */
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] || 0;
};

/**
 * Sets the variable value for the given variable id
 *
 * @param {number} variableId - The variable id to set
 * @param {number} value - The value to store in the variable
 */
Game_Variables.prototype.setValue = function(variableId, value) {
    if (variableId > 0 && variableId < $dataSystem.variables.length) {
        if (typeof value === "number") {
            value = Math.floor(value);
        }
        this._data[variableId] = value;
        this.onChange();
    }
};

/**
 * Processing when a variable value is changed
 */
Game_Variables.prototype.onChange = function() {
    $gameMap.requestRefresh();
};