GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Key for saving and load attribute

SuperbucSuperbuc Posts: 17Member
edited November -1 in Working with GS (Mac)
I'm sorry but I cannot understand how use "key" value in saving and loading attributes.
Imagine I can play with 2 different players, male and female, and each one has a score, a level as example.
Must the key be different form one to other or not ?

example:
Male Player:
attribute: score.level ; key: MALE
attribute: game.level; key: MALE

Female Player:
attribute: score.level ; key: FEMALE
attribute: game.level; key: FEMALE

Or instead a key different for each, as :

attribute: score.level ; key: SCORE.LEVEL.MALE
attribute: game.level; key: GAME.LEVEL.MALE

?

Thank you

Comments

  • quantumsheepquantumsheep Posts: 8,188Member
    Different key for each.

    Every attribute you save should have a unique key attached to it.

    Remember you can only check saving on your phone through the viewer, not in preview mode on your Mac.

    Additionally, the key is case sensitive. So if you use Male to save, and male to load, it won't work - they both have to be the same!

    Hope that clears up any confusion!

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: http://www.quantum-sheep.com

  • jonmulcahyjonmulcahy Posts: 10,383Member, Sous Chef
    When I save values I always make the key the exact same value as the attribute I'm saving

    So, if I have an attribute called lastCompletedLevel, I make my key the same name. It makes it easier to keep track of.
  • quantumsheepquantumsheep Posts: 8,188Member
    Yep, I do exactly the same.

    I also just use lowercase - easier NOT to make mistakes ;)

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: http://www.quantum-sheep.com

  • SuperbucSuperbuc Posts: 17Member
    Ok, thanks, now it's more clear. Even if I don't understand why there's a key !
  • jonmulcahyjonmulcahy Posts: 10,383Member, Sous Chef
    i think they are saving values to a back end database and the key is just the identifier. i'm not sure exactly how they are programming it, but I imagine there is a database with a table for all our values. column 1 is the primary key. column 2 is the value.

    the key you create goes into the first column and needs to be unique. this is how the game engine will find the value you want to save.

    that's how I imagine it anyways.
  • thebitmasterthebitmaster Posts: 75PRO
    It's also *very* important to realize the keys *have* to be in quotes.

    "mykey"

    not

    mykey

    The second version will causes keys to overwrite each other, which can cause major debugging headaches. I've just wasted two days because that *isn't* mentioned in the docs anywhere, and no error is flagged when it's done improperly.
  • gyroscopegyroscope I am here.Posts: 6,577Member, Sous Chef, PRO
    thebitmaster said:
    It's also *very* important to realize the keys *have* to be in quotes.

    "mykey"

    not

    mykey

    The second version will causes keys to overwrite each other, which can cause major debugging headaches. I've just wasted two days because that *isn't* mentioned in the docs anywhere, and no error is flagged when it's done improperly.

    Wow, I didn't know that; most useful advice, thanks.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • thebitmasterthebitmaster Posts: 75PRO
    Another wrinkle from GameSalad Support:

    Whenever you want to type custom text into the expression editor, you need to stay away from hitting that little "e" at the end. Otherwise, GameSalad thinks it's an expression parameter and it nulls out. If you DO hit the little "e" at the end, just click "remove expression" and it should resolve your issue.

    So the fix :

    - Create your save/load attributes within your actors

    - Type in your "levelswon" and "totalscore" keys (don't hit the "e"!)
  • tenrdrmertenrdrmer Posts: 9,934Member, Sous Chef, Senior Sous-Chef
    thebitmaster said:
    It's also *very* important to realize the keys *have* to be in quotes.

    "mykey"

    not

    mykey

    The second version will causes keys to overwrite each other, which can cause major debugging headaches. I've just wasted two days because that *isn't* mentioned in the docs anywhere, and no error is flagged when it's done improperly.

    Where did that info come from? I have never place quotes on my keys an I have never had a game not save and load the proper info.

    Also @ QS For his comment from months ago. In the preview Clicking the reset icon is the same as closing and re opening on a device. Just make sure you have previewed from the beginning otherwise clicking that reload will not work right. But that is a great quick little way to test your save an loads.

    It's not my fault I never learned to take responsibility for anything. ;)

  • carlosacj36carlosacj36 Posts: 54Member
    use the same string as a variable and as a key, and problem solved
This discussion has been closed.