How do I update a WebStorage local key?

0 favourites
  • 8 posts
From the Asset Store
Fantasy Game includes more than 600 sound effects inspired by hit computer games like World of Warcraft and Diablo.
  • Hi,

    I struggle with setting the value of a key. I want it to overwrite the existing value every time I play a level, so that you at all times can see the latest score on each level.

    What I have done so far is to create a global variable which I use as a timer (one for each level), adding 1 to this variable every second.

    Then, at the end of the level, I do something like: Set local key "Time_LevelX" to Timer_LevelX

    Then I display this in a level selection layout like this: Set text to WebStorage.LocalValue("Time_LevelX")

    The problem is that is seems to only be storing the key the first time I finish the level. If I try again, it doesn't get updated, and I'm stuck with same time every time.

    Could someone please explain why is it not updating the value?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have also tried to remove the key on start of layout, and then something like:

    Local key "Time_LevelX" not exists -> Set local key "Time_LevelX" to Timer_LevelX (the global variable)

    However, this way it is just deleted when I start the layout and never created again...

  • Could you please provide a capx or show your events so we can see how you have set this up?

    If you are saving the value the correct way, it should work..

  • Could you please provide a capx or show your events so we can see how you have set this up?

    If you are saving the value the correct way, it should work..

    Sure, sorry about that. It's a bit messy, hope you'll understand.

    I'm using quite a few other keys, and they are working fine. However, this "Time_Level1" seems to be set only the first time I complete the level for some reason. I was hoping to update it every time I run the level.

    [attachment=1:1tolgfdh][/attachment:1tolgfdh]

    And here is a part of my level selection layout, where I display the value (which is working fine it seems).

    [attachment=0:1tolgfdh][/attachment:1tolgfdh]

    I really don't see what the problem is.

  • well you are setting localkey level1 to 3 and you are not resetting it I guess, so those webstorage commands are never executed again..

  • well you are setting localkey level1 to 3 and you are not resetting it I guess, so those webstorage commands are never executed again..

    Hm, the local key "Level1" is not related here. This is controlling something else and is behaving as expected.

  • Ok, if you are sure..

    Although it is related for one of the conditions is to check the local key level1 and if that local key is changed, but not changed back..

    But I'm just responding to what I see in your events, maybe you are changing it back to 0..

  • Ok, if you are sure..

    Although it is related for one of the conditions is to check the local key level1 and if that local key is changed, but not changed back..

    But I'm just responding to what I see in your events, maybe you are changing it back to 0..

    Ah, you sir, are a genius. Not sure why I couldn't see that before.. Of course it won't update "Time_Level1" as "Level1" always will be 3 after first completing the level. With some black magic and sorcery I was able to add another event that enabled me to update the value each playthrough.

    Thanks

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