Sunday, January 24, 2010

Local Storage Plugin

A new plugin has just been committed, local storage, which lets you store key-value pairs locally. It's currently being used to persist the high scores in the Racing game.

Usage:
  • Add intensity.components.local_storage to the proper place ([Components] list) in your settings.cfg, so the plugin will be loaded.
  • In your scripts, do CAPI.signalComponent('LocalStorage', 'read|KEY'); to read the value for KEY. You will get in response a string (all output from signalComponent is in string form), so do eval() on that. The result will be a list of responses from components. Normally you will have only one storage component, so just get the value at index [0].
  • To write values, do CAPI.signalComponent('LocalStorage', 'write|KEY|VALUE'); to write that KEY-VALUE pair.
That's basically it. See also the source file for some technical docs and notes.

No comments:

Post a Comment