Webstorage - how to save ingame information

1

Stats

6,708 visits, 11,484 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 18 Feb, 2012. Last updated 19 Feb, 2019

Sometimes it is tough to find the right information even within tutorials since the title sometimes obfucates the content.

Now, this short tutorial will cover the WebStorage-Plug in.

Things to consider

First of all, you have to understand, that due to data security and safety, one is "unable" to access the local harddrive by a HTML tag or element. To do this, you have to use some sort of programing technique that crosses this border like PHP or JAVA. Not even JavaScript is - as far as I know - able to cross this line.

The only way for HTML to "store" information on the local client is useing the cookie technology. This is where the WebStorage Object comes it to play.

You have the choice between two different types of cookies. One that only exist durring the current brwoser session, ie. the information get lost, as soon as the browser is closed.

An the "local" typ which persist as long as the cookies are not erased.

Useing cookies to store data

Actually this concept is quite simple. You can store any string into a cookie. To retrieve the data, you have to link the string to a "key"

This is an example out of my current project:

Here the current SCORE gets saved to a cookie holding the key "HighScore". You do not have to worry about actualy storing the cookie, this is done by the plug-in.

Now, how to retrieve the information? This is as easy as saving the data:

Here the data that is bound to the key "HighScore" gets retrieved.

So, you can store and retrieve all data, that you can store in a string.

  • 0 Comments

Want to leave a comment? Login or Register an account!