How do I update a WebStorage local key?

Get help using Construct 2

Post » Sun Sep 14, 2014 3:56 pm

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?
B
14
S
3
Posts: 123
Reputation: 1,571

Post » Sun Sep 14, 2014 4:20 pm

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...
B
14
S
3
Posts: 123
Reputation: 1,571

Post » Sun Sep 14, 2014 4:59 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Sep 14, 2014 5:08 pm

LittleStain wrote: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.

LocalKey.png


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

LevelSelectionLayout.png


I really don't see what the problem is.
You do not have the required permissions to view the files attached to this post.
B
14
S
3
Posts: 123
Reputation: 1,571

Post » Sun Sep 14, 2014 5:12 pm

well you are setting localkey level1 to 3 and you are not resetting it I guess, so those webstorage commands are never executed again..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Sep 14, 2014 5:15 pm

LittleStain wrote: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.
B
14
S
3
Posts: 123
Reputation: 1,571

Post » Sun Sep 14, 2014 5:18 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Sep 14, 2014 5:23 pm

LittleStain wrote: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 :)
B
14
S
3
Posts: 123
Reputation: 1,571


Return to How do I....?

Who is online

Users browsing this forum: Sparkz, Yahoo [Bot] and 1 guest