How do I use the LocalStorage Plugin?

1 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • I just tried implementing localstorage into my game, and I found an issue that I would like to hear anyone's opinion on.

    I am using an array to store which levels have been cleared, and which is still locked because the previous levels haven't been cleared. The problem I am having is that previously, I would load the array and set each button's animation frame to display the appropriate frame as a sub event to the on start of layout event. This ensured that everything was set up immediately at the start, and the player will not notice it.

    But since LocalStorage can only be used as an event and not sub event, I placed the button animation frame loading events as a sub event for the On item get event, since I thought it made the most sense to put it there and have it load immediately once the value has been retrieved, and also to ensure it only loads once. But the problem is that loading the LocalStorage takes a small but noticeable amount of time. When loading the page, you will notice the button frames changing from default animation frame to the loaded one.

    I was curious what others are doing to counter this loading time to ensure that it isn't noticeable for the player? Is the only option to use an earlier page to load all the values than when you go to the next page, do not reset all global variables but use the earlier loaded variables so you can add it as a sub event to the on start of layout event? Or is there another way to get it to load much faster?

  • I just got it to work right, i changed the key and variable names and then it worked. Thanks for the help!

    Then an old LocalStorage key with the same name was in your cache of your browser. In this case just purge the cache & cookies in your browser.

    Regards

    Andreas

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I just tried implementing localstorage into my game, and I found an issue that I would like to hear anyone's opinion on.

    I am using an array to store which levels have been cleared, and which is still locked because the previous levels haven't been cleared. The problem I am having is that previously, I would load the array and set each button's animation frame to display the appropriate frame as a sub event to the on start of layout event. This ensured that everything was set up immediately at the start, and the player will not notice it.

    But since LocalStorage can only be used as an event and not sub event, I placed the button animation frame loading events as a sub event for the On item get event, since I thought it made the most sense to put it there and have it load immediately once the value has been retrieved, and also to ensure it only loads once. But the problem is that loading the LocalStorage takes a small but noticeable amount of time. When loading the page, you will notice the button frames changing from default animation frame to the loaded one.

    I was curious what others are doing to counter this loading time to ensure that it isn't noticeable for the player? Is the only option to use an earlier page to load all the values than when you go to the next page, do not reset all global variables but use the earlier loaded variables so you can add it as a sub event to the on start of layout event? Or is there another way to get it to load much faster?

    Hello rekjl

    I'm facing the same problem. I excluded all my LocalStorage function in an extra event sheet called 'es_LocalStorage' and included the event sheet in all event sheets where I need the loading function. When my levelselection screen comes up the player first sees all levels as locked, then when the LocalStorage has been loaded from the LocalStorage the LevelsButton Animation changes to unlocked.

    It's just a little time frame but it is noticable.

    It helps if you use a menu and a levelselection as separate layouts. Then you can fetch the array at the menu, so the values are already available in the levelselection screen. Otherwise I have no idea at the moment to work around this issue.

    Regards Andreas

  • Yup I ended up doing that, had to do a few changes to my game but made sure everything loaded in the first layout, than manually reset all global variables one by one in the on start of layout event. My first page also displayed the percentage of levels completed, so to counter the time it takes to correctly display it, I added an animation of the numbers moving at random before showing the correct one after 1 second. Haha at least I think the player will not notice that it was there to cover up the slow loading.

  • My variable is NaN which I heard is "Not a Number" but I followed all the instructions:

    Screenshot of the events:

    prntscr (dot) (com) / 8d23zg

    Screenshot of score:

    prntscr (dot) (com) / 8d24lo

    What is my problem?

    Edit: So apparently I am not able to post links... So that's why the links look like that.

  • My variable is NaN which I heard is "Not a Number" but I followed all the instructions:

    Screenshot of the events:

    prntscr (dot) (com) / 8d23zg

    Screenshot of score:

    prntscr (dot) (com) / 8d24lo

    What is my problem?

    Edit: So apparently I am not able to post links... So that's why the links look like that.

    Hello,

    can you provide a capx example or a screen shot of your code?

    Regards

    Andreas

  • Nevermind actually, I figured it out.

  • On your second layer all you did was:

    Set text to player coins, set player coins to player coins in local storage, and make a button.

    You didn't fetch the value at all, and set it to the text... try that in start of layout...

  • The plug-in is automatically included in the latest version. So, just download the latest stable version of C2, you have the plug-ins included.

  • AndreasR

    can you help me out please!?

    i was used to webstorage (wich was fine by mine opinion) and now its gone and im stuch with this LocalStorage that i just dont get...

    I have numerical value stored under key "X"

    and i want to compare it and see if that value is equal or under "9" and than ad zero infront of it so that value looks like "09"

    Websorage had "compare key value" and that worked excellent for me... but no im stuck with this crapy LocalStorage and dont know how to proceed...

    HELP!!!!

  • AndreasR

    can you help me out please!?

    i was used to webstorage (wich was fine by mine opinion) and now its gone and im stuch with this LocalStorage that i just dont get... <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    I have numerical value stored under key "X"

    and i want to compare it and see if that value is equal or under "9" and than ad zero infront of it so that value looks like "09"

    Websorage had "compare key value" and that worked excellent for me... but no im stuck with this crapy LocalStorage and dont know how to proceed... <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    HELP!!!!

    Hello irina

    I worked out an example for you <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    https://www.dropbox.com/s/qa48otm534p8k ... .capx?dl=0

    This should work for you.

    Regards

    Andreas

  • AndreasR

    Thank you very much!!!

    now i see the logic of it.

    by the way... i have error in FF when i run your example

    Javascript error!

    UnknownError

    http://192.168.5.2:50002/LocalStorage_plugin.js, line 33 (col 0)

    This may be a bug in Construct 2 or a third party plugin or behavior - please report it to the developer following the bug report guidelines. Subsequent errors will be logged to the console.

    can you check please?

  • AndreasR

    Thank you very much!!!

    now i see the logic of it.

    by the way... i have error in FF when i run your example

    Javascript error!

    UnknownError

    http://192.168.5.2:50002/LocalStorage_plugin.js, line 33 (col 0)

    This may be a bug in Construct 2 or a third party plugin or behavior - please report it to the developer following the bug report guidelines. Subsequent errors will be logged to the console.

    can you check please?

    It works fine on my end. I tested it with Firefox and it works.

    But I have the same issue on my MacBook running Windows 10. I'm not sure why this happens only there. I will update C2 and will let you know then.

    Regards

    Andreas

  • AndreasR

    small problem in this logic...

    this example sucessfuly changes variable but it wont change/correct localstorages value it self (wich is what i need).

    when i set that global variable from 15 to 9 and set

    LS <= 9 | LS set item "example_key" to "0" & str(LocalStorage.ItemValue)

    every time i run it adds "0" in front of current value so i end up with value like: 000009

    if i add clear storage on start of layout then its allways just "9".....

    buhuhuhuhu... i miss my WebStorage... it was so simple and easy...

    PS: regarding that JS error... i run Latest stabile release 212.2

  • AndreasR

    small problem in this logic... <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    this example sucessfuly changes variable but it wont change/correct localstorages value it self (wich is what i need). <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    when i set that global variable from 15 to 9 and set

    LS <= 9 | LS set item "example_key" to "0" & str(LocalStorage.ItemValue)

    every time i run it adds "0" in front of current value so i end up with value like: 000009

    if i add clear storage on start of layout then its allways just "9".....

    buhuhuhuhu... i miss my WebStorage... it was so simple and easy... <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

    PS: regarding that JS error... i run Latest stabile release 212.2

    I'm not quite sure what you want to achieve. If you save the key like "09" it must be a string. But then you cannot compare it with less or equal 9. You must converte it back to an integer first in order to do that.

    I updated the example, please check it.

    https://www.dropbox.com/s/qa48otm534p8k ... .capx?dl=0

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)