Script:Persist.js
From Spherical
persist.js lets you store variables in persons and maps, and use them in event scripts.
At its simplest, you can store simple quest information, e.g. if you've talked to an NPC, or collected an item. Power users can take full advantage of JavaScript, and write templates for common person patterns, e.g. one-line townsfolk, store keepers, inn keepers, save points, chests, items, door switches, bosses blocking passages, and warps.
It helps you to organise your game data. If you ever got sick of making global variables and confusing data structures to hold your game info, this is your answer.
Download
- persist.js (17.9 KB JavaScript file)
-
persist.js demo game(15.6 KB ZIP archive, requires Sphere)
The code (embedded Gist)
<gist>5702052</gist>
Quick start
- Download persist.js into your scripts/ folder.
- Put this in your game function:
RequireScript("persist.js"); function game() { persist.init(); // ... }
- Create a maps/ folder in your scripts folder, so it looks like scripts/maps/
- For each some_map.rmp, make a new script file scripts/maps/some_map.js
- 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."); } } })