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

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Actually i have:

    [quote:18fl4in3]

    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:

    [quote:18fl4in3]

    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

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

    -

    I posted a feature request to improve this:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    [quote:mp3b8pik]

    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

    [quote:mp3b8pik]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

  • 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

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