Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Status update 11th March 2012

Looks like storage objects will be making an appearance in a Warzone near you sometime in the future (wink)

See: http://forums.wz2100.net/viewtopic.php?f=35&t=8756&start=150#p97205 for details.

Overview

I'm becoming increasingly convinced that storing JS state in .ini files is the wrong direction to be taking.

...

And those errors only tend to surface when an end-user runs in to bugs after saving then loading a game.

Today comes before tomorrow

...

  • Values can be any data type supported by JSON (in a browser, they'd have to be strings). Supported object types are currentlyJSON currently has native support for:
    • Object
    • Array
    • String
    • Boolean
    • Number
    • Null
  • I've added toJSON() and fromJSON() methods.

...

After sessionStorage.js is included in the JS environment, the contents of the playerX_sessionStorage.js file are loaded and then pumped in via sessionStorage.fromJSON(data) (where 'data' is the string representation of the contents of the playerX_sessionStorage.js file).

That's it.

Future development:

...

localStorage

If the sessionStorage idea proposed above gets accepted, then an obvious next-step would be to implement localStorage.

...

Inside the localStorage.setItem() method, it would do the normal stuff - in other words update its own internal data object. But then it would also call setLocalStorage(me,key,JSON.stringify(val))

When setLocalStorage is called, the C++ code would do something like this:

Code Block
// simplified pseudo code
 
function setLocalStorage(fromPlayer,key,val) {
  // work out what script called setLocalStorage (eg. nullbot_1.1.js):
  var playerEngine = getEngineForPlayer(fromPlayer);
  var playerScript = playerEngine.scriptFileName;
  // update all other players where applicable:
  for (var i=0; i<maxPlayers; i++) {
    // no need to update the script that triggered setLocalStorage():
    if (i != fromPlayer) {
      // is this player's engine running same script as the calling script?
      var engine = getEngineForPlayer(i);
      if (engine.scriptFileName == playerScript) {
        // update it's localStorage with the new data
        engine.globalObject.localStorage.setItem(key,val,false,true); // 4th param tells setItem() not to call setLocalStorage()
      }
    }
  }
  // now persist the localStorage data to file on disk
  var jsonData = playerEngine.globalObject.localStorage.toJSON();
  var fileName = "path/to/config/folder/"+playerScript+"_localStorage.js";
  createOrReplaceFile(filename,jsonData);
}

...