The WebStorage object can store data locally on the user's computer between sessions. For example, it can be used to store the last save checkpoint, and restore the player's progress if they come back the next day.
Storage per domain
The WebStorage object associates all stored data with the current domain. For example, all games running on scirra.com share the same data, but games running on facebook.com use a different set of data and cannot access any data saved from scirra.com.
Most browsers implement a maximum size of the data that can be stored with WebStorage - 5mb is a common limit.
Local vs. Session storage
The WebStorage object allows data to be stored in two places: Local storage and Session storage.
Local storage is permanent (until the user clears their cache). If the user comes back the next day, local storage still has the saved data.
Session storage only lasts with the current browser session. If the user comes back the next day, session storage is empty again.
Using WebStorage
The WebStorage object uses a very simple storage model: values are stored under named keys. For example, the value 100 could be stored for the key score with the action Set local value "score" to 100. Similarly the value John can be stored for the key name. Then the expression WebStorage.LocalValue("score") returns 100 and WebStorage.LocalValue("name") returns "John", and these values persist between sessions. (If session storage was used instead, the values would only last as long as the browser session.)
WebStorage conditions
Local/session key exists
Check whether a value has been saved for a key in either local or session storage.
WebStorage actions
Clear local/session storage
Reset either local or session storage to empty for this domain, with no data stored.
Remove local/session value
Delete a key (and its associated value) from local or session storage. It will no longer exist after this action.
Set local/session value
Store a value (string or number) for a key in local or session storage. If the key does not exist it is created, otherwise its value is simply updated.
WebStorage expressions
LocalAt
SessionAt
Return the value at a zero-based index if all the keys in storage are listed in alphabetical order. Useful for listing all stored data.
LocalCount
SessionCount
Return the number of keys that exist in storage for this domain.
LocalKeyAt
SessionKeyAt
Return the key name at a zero-based index if all the keys in storage are listed in alphabetical order. Useful for listing all stored data.
LocalValue
SessionValue
Retrieve the value stored for a key in storage. If the key does not exist this returns 0.