New LocalStorage simplified with a temp Dictionary

Stats

1,973 visits, 2,993 views

Translations

This tutorial hasn't been translated.

Tools

Update 02.06.17: Fixed Urls for Demo and Download

Update 22.09.15: Online demo, fixed misspelling

Download the example here

Try the demo here

Many of you are struggling with the localstorage plugin.

Each new item causes a new check of exists, then get, then set ...

I show you my solution, that simplifies that with just using 2 functions!

How it works

On start of Layout, if the DB(DataBase) doesn´t exist, it will be initialised with a empty string value („“).

All values will be saved to localstorage and copied to a dictionary.

You don´t need to worry about get, set, exists item anymore!

You only have to use 2 Functions! The rest is done automatically :)

GetLocal(„AnyKey“), will look up your dictionary for the specified key, if it exists, it will return the value, else it will insert the key with a „0“ value and update your localstorage.

SetLocal(„AnyKey“, „AnyValue“), wich will look up your dictionary for the specified key, if it exists, it will be updated by the second parameter, else it will be inserted and update the localstorage automatically.

Functions Explanation

GetLocal

- First Param is the key your are searching for

- this functions return value is the value of the specified key, or 0 if the key didn´t exist.

SetLocal

- First Param is the key you will insert or update

- Second Param is the value that will be inserted

- this functions return value is the value of the inserted or updated key

DeleteLocal

- First Param is the key of the item that you want to delete (if it exists)

Steps to including in your Project

- Add the plugins and name them:

-- LocalStorage, One Dictionary => name it „Locals“, Browser => For Debug

- Include my Event-Sheet „Locals“ (copy and paste)

- In your Main-EventSheet add the Event „On item LocalName get“

-- this ensures, that my Local-EventSheet did its job on start ;)

- Add logic after your needs

Examples

1st Example:

- You want to get the HighScore value and compare it with CurrentScore

- If CurrentScore is higher, then save CurrentScore to HighScore

All you need to do is:

if CurrentScore > GetLocal(„HighScore“) => SetLocal(„HighScore“, CurrentScore)

2nd Example:

- You want to get the value of HighScore and write it to a text-element.

All you need to do is:

TextElement set text to GetLocal(„HighScore“)

  • 0 Comments

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