[r202] LocalStorage loses values after refresh or restart

0 favourites
  • 3 posts
From the Asset Store
In this template the music plays without looping in your game
  • Problem Description

    Here's the thing i tried to do - start a layout - set localstorage value - close and back again or refresh the page - check if item exist and set text to its value and if it's value equals to 1 do something.

    Attach a Capx

    I don't know why, but i can't attach it, i don't have attachements button. Here's the link.

    https://yadi.sk/d/bQ9xA43Kfz969

    Description of Capx

    Text object + Sprite object + Touch object. On start of layout check if item "Value" exist, if exist set text to item's value and if item's value equals 1 - rotate sprite 34 degrees clockwise. On first start the localstorage "Value" item is not exist, so you need to touch the sprite to Set "Value" item to 1 and restart the layout. On restart you'll see that text is now showing 1 (items value) and sprite is rotated, you can tap sprite again and again to restart the layout and see that everything is working as it should, everytime the layout restarts "Value" item sets to text and compares right. Now refresh the page (F5, browsers refresh) or close and start the preview again, local storage triggers the exist condition but gives us the empty value, so text is empty text, and it is not equals 1 anymore and the sprite is not rotated because of that.

    Steps to Reproduce Bug

    • Start preview
    • Touch the Sprite to Set "Value" item to 1 and restart the layout
    • On restart you'll see that text is now showing 1 and sprite is rotated, as it should
    • Now refresh the page (F5, browsers refresh) or close and start the preview again, the result must be the same as after restart of layout but it's not, local storage triggers the exist condition but gives us the empty value, and value of item "Value" is not equals 1 anymore

    Observed Result

    Local storage triggers the exist condition but gives us the empty value

    Expected Result

    Local storage always gives me the values that i stored.

    Affected Browsers

    • Chrome: (YES)
    • FireFox: (YES)
    • Internet Explorer: (YES)

    Operating System and Service Pack

    Windows 7 64bit latest all.

    Construct 2 Version ID

    r202

  • There are two issues here:

    1) You set a value then try to retrieve it again (after restarting the layout) before you are sure that it has actually been written to storage. You should wait until 'On item set' triggers before restarting the layout.

    2) 'On item exists' does not set the ItemValue expression. I found that it can since the code happens to have the value available when it fires that trigger, so I added support for that.

    #1 is your fault, #2 is fixed for next beta.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1) You set a value then try to retrieve it again (after restarting the layout) before you are sure that it has actually been written to storage. You should wait until 'On item set' triggers before restarting the layout.

    My description is wrong a little i guess, i don't have any trouble after restart of layout, and i see no trouble with this, trouble starts only after restart of preview (refresh browser page or close and start again), so no trouble with #1, but thanks for the info and thanks for #2 fix.

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