How do I manage the creation of "trophies" using storage

Get help using Construct 2

Post » Fri May 20, 2016 8:07 am

Actually i have:

On start layout > Check "key_trophy1" exists.

On Item "key_trophy1" exists > Get item "key_trophy1"

On Item "key_trophy1" get > Set "trophy1" to localStorage.ItemValue

On Item "key_trophy1" missing > Set "trophy1" to 0


And that only for the start to check if exists and set a value in case of missing, after that in case i unlock a trophy i do this:

On trophy1 = 1 > Get item "key_trophy1"

On Item "key_trophy1" get > Set item "key_trophy1" to 1



So, There is no other way to do this thing more simple? Or i have to do it for each trophy i create? :S
B
23
S
10
G
3
Posts: 538
Reputation: 4,426

Post » Sat May 21, 2016 8:40 am

So, there is no other option to do it more simple?

-

I posted a feature request to improve this:
viewtopic.php?f=146&t=173092&p=1037976#p1037976
B
23
S
10
G
3
Posts: 538
Reputation: 4,426

Post » Sat May 21, 2016 8:53 am

You might be able to do a thing whereby you put the variables for all of the trophies into one string in storage and then parse them back out with tokens.

On start layout > Check "key_trophies" exists.

On Item "key_trophies" exists > Get item "key_trophies"

On Item "key_trophies" get > Set "trophy0" to tokenat(localStorage.ItemValue, 0, "~")
> Set "trophy1" to tokenat(localStorage.ItemValue, 1, "~")
> Set "trophy2" to tokenat(localStorage.ItemValue, 2, "~")
> Set "trophy3" to tokenat(localStorage.ItemValue, 3, "~")
etc

On Item "key_trophies" missing > Set all trophies to 0


and for unlocking

On Item "key_trophies" get > Set item "key_trophies" to trophy0 & "~" & trophy1 & "~" & trophy2 & "~" & trophy3 (etc)


So what you're actually putting in storage is just one string that might end up looking like this: "1~1~1~0~1~0" etc, where each number represents whether or not you've got trophy 0, trophy 1, trophy 2, etc.

This is off the top of my head so the logic might be a bit wonky but that's the approach I'd take. You might be able to do a crafty for-each loop or something to simplify it further too :)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 201
Reputation: 3,460

Post » Sat May 21, 2016 8:59 am

Orrrrr, what about putting all of your trophy data into array cells rather than individual variables, and then just saving out the whole array to JSON and putting THAT in storage? That's probably an even better idea :)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 201
Reputation: 3,460


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 9 guests