How do I Save Location in LocalStorage

Get help using Construct 2

Post » Thu Jan 05, 2017 10:37 am

Hey all, i try to save the Location of Levelselect into Localstorage... But it doesnt work. I will save the unlocked level into Localstorage. If the player restart the game, the latest unlocked levels should appear.

Hope u know what i mean :D

My Code:
Image
B
19
S
5
G
3
Posts: 44
Reputation: 2,727

Post » Thu Jan 05, 2017 12:36 pm

The first action, on start - it needs separating.

Essentially, everything from local storage is brought in 'blobs' - every time you retrieve anything, it has to check the blob, then fetch that blob first - which is two whole interactions, each of which take (a very small amount of) time. So when you use 'Check item exists' you have to use another action to call when the blob check has finished (otherwise it will try and do it in the same tick - which won't work, because the blob hasn't been... blobbed (?) yet).

The action you need is 'On item exists [CurLocation]' - then use 'Get item [CurLocation]' action in that event. Then you need another event 'On get item [CurLocation]', in which you can FINALLY set the variable! :P Seems crazy I know.
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 237
Reputation: 2,296

Post » Thu Jan 05, 2017 1:39 pm

Ok now i have this:

Image

but it doesnt work... everytime if start the game and unlock the next level it doenst save. On any restart the levels are resetet =( any idea?
B
19
S
5
G
3
Posts: 44
Reputation: 2,727

Post » Thu Jan 05, 2017 3:00 pm

You aren't setting the CurLocation variable. You don't need event 3. In event 2 replace the 'Get item' with CurLocation = LocalStorage.ItemValue.
You should add 'On item missing', and set CurLocation = 1, and remove event 7.

LocalStorage takes time to read. You shouldn't really do anything that relies on CurLocation until either 'exists' or 'missing' is triggered.
ImageImageImage
B
71
S
21
G
221
Posts: 3,650
Reputation: 124,229

Post » Thu Jan 05, 2017 4:28 pm

Doesnt work for me:

Image


The Tutorial i have done is: https://www.youtube.com/watch?v=0M_kR6K ... UaM&t=644s
B
19
S
5
G
3
Posts: 44
Reputation: 2,727

Post » Sat Jan 07, 2017 1:02 am

On start - check item exists
On item exists - get item
On get item - set variable to localstorage.itemvalue
The LEVEL GENERATOR TOOLKIT



24 functions dedicated to producing randomly generated terrain for all kinds of games.
B
25
S
7
Posts: 237
Reputation: 2,296

Post » Sat Jan 07, 2017 9:29 am

Thank you. But where is the current location stored? It must be stored somewhere the current levels so that they are there again when restart

My Code Now:

Image
B
19
S
5
G
3
Posts: 44
Reputation: 2,727


Return to How do I....?

Who is online

Users browsing this forum: lolsuperscratch, RobertMKD, tarek2 and 10 guests