Source: Game_Switches.js

Game_Switches.js

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

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

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

/**
 * Get the switch value for the given switch id
 *
 * @param {number} switchId - The switch id
 * @return {boolean} The value stored in the switch
 */
Game_Switches.prototype.value = function(switchId) {
    return !!this._data[switchId];
};

/**
 * Set the switch value for the given switch id
 *
 * @param {number} switchId - The switch id
 * @param {boolean} value - The value to store in the switch
 */
Game_Switches.prototype.setValue = function(switchId, value) {
    if (switchId > 0 && switchId < $dataSystem.switches.length) {
        this._data[switchId] = value;
        this.onChange();
    }
};

/**
 * Processing when a switch's value is changed
 */
Game_Switches.prototype.onChange = function() {
    $gameMap.requestRefresh();
};