persist.js framework

tung's picture

persist.js is a framework for the Sphere RPG engine that lets you store persistent data and code with persons and maps. It can be used for very powerful techniques, such as abstracting common person behaviours, and organising code.

Download

Quick start

  1. Download persist.js to your game's scripts/ directory.
  2. Put the following in your game function:
    RequireScript("persist.js");
     
    function game()
    {
      persist.init();
      // ...
    }
  3. Create a maps/ directory in your scripts/ directory, so it looks like scripts/maps/
  4. For each some_map.rmp, make a new script file scripts/maps/some_map.js
  5. Start writing in scripts/maps/some_map.js:
    /**
     * This will greet the player when they enter the map,
     * and let the person named "Billy" say how many times
     * the player has spoken to them.
     */
     
    ({
      visited: false,
     
      enter: function (self) {
        if (!self.visited) {
          Say("Welcome to " + GetCurrentMap() + "!");
          self.visited = true;
        }
      },
     
      Billy: {
        times: 0,
     
        talk: function (self) {
          self.times += 1;
          Say("Hi! We've spoken " + self.times + " before.");
        },
      },
    })

External links