mwg API
    Preparing search index...

    Class GameState

    Global switches and variables - the two pieces of state an RPG's events read and write most, kept as plain maps rather than anything fancier so mwg/core's SaveSystem can serialise them like any other plain data.

    import { GameState } from '@datamoc/mw_games/rpg';

    const state = new GameState();
    state.setSwitch('metShopkeeper', true);
    state.setVariable('gold', 50);

    console.log(state.switch('metShopkeeper'), state.variable('gold'));

    const saved = JSON.stringify(state.toJSON());
    const restored = GameState.fromJSON(JSON.parse(saved));
    Index
    • Parameters

      • name: string
      • value: boolean

      Returns void

    • Parameters

      • name: string
      • value: number

      Returns void

    • Returns { switches: [string, boolean][]; variables: [string, number][] }

    • Parameters

      • data: { switches: [string, boolean][]; variables: [string, number][] }

      Returns GameState