Saving attribute/image when switching scenes

Hey so I have a drop down menu on one of my scenes and one of the buttons is a favorite button with a star image.When the user presses the button it changes the image to a filled in yellow star. Also on this menu is the home button, when you press it it brings you to the home screen. The problem is that when i press the star, then go home or change scenes and then go back to the screen with the star, the star will no longer be the filled in image. Im thinking that somehow the attribute is being reset when i change scenes, so my question is how do i make it so this doesn't happen?
Note: i made a game attribute called FavoriteButton and use that for the basis of changing my image.

Comments

  • AdrenalineAdrenaline Member Posts: 523
    I may be wrong, but try thinking of it this way:

    if the attribute FavoriteButton is a scene attribute, it's being reset when the user leaves that scene. So when they come back, it's as if they never changed it.

    Use the save and load behaviors to make a key that holds the state of this attribute. Whenever the user presses the button, drop in a save behavior and associate it with a key that you make up. Then, add a load behavior to something that runs as soon as the user enters the scene. Load that same key you just created. This will load the state of FavoriteButton and should remember how the star needs to appear.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2013

    Hi @Crumby Entertainment

    scene attributes, if they're not saved and reloaded, do reset if you leave the scene and come back to it again.

    So you have couple of options: just before you leave to go the scene, use a Save Attribute behaviour for each of your attributes you want the values kept, and in an actor outside of the screen, put a Load Attribute behaviours.

    Alternatively, use game attributes, then you won't need any Load Attribute behaviours as these are "remembered" anywhere in the game/app.

    Either way, you'll need to use Load Attribute behaviours for when the game is first opened each time to carry on from where you left off, otherwise even the game attributes will be reset back to their original values.

    You could use a Table to load and save your attributes, if you wanted, in place of the save and load behaviours, but remember to save these in a copy of the table, otherwise you'll overwrite the original values

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

  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    edited December 2013
    Thanks for the quick responses. So I do have a game attribute, not a scene attribute but the image still resets after i change scenes and come back...Maybe it has something to do with my code. Here is what i have below: game.favoritebutton is my integer game attribute.

    When Touch is pressed{
    do-->Set game.favoritebutton to: (game.favoritebutton+1)%2
    else--> (NOTHING HERE) }

    Then i have another rule:
    If: game.favoritebutton = 1 {
    do-->when touch is pressed
    { do-->set image to yellow star
    else--> (NOTHING HERE) }
    else--> Set image to blank star }

    Thanks again for the help!
  • pHghostpHghost London, UKMember Posts: 2,342
    edited December 2013
    @Crumby_Entertainment

    In the second rule, remove:
    do-->when touch is pressed

    All you need in the second rule is:
    IF: game.favoritebutton = 1
    CHANGE IMAGE: yellow_start
    OTHERWISE:
    CHANGE IMAGE: blank_star

    What is happening is that when you come back, the second rule states you need to touch the actor in order to see the filled star (every single time), otherwise it will stay blank.

    So you need one rule as a controller, and the second one to react purely to the output of the controller, nothing else.
  • CrumbyEntertainmentCrumbyEntertainment Member, PRO Posts: 32
    Thanks a lot that worked!
  • pHghostpHghost London, UKMember Posts: 2,342
    Great!
Sign In or Register to comment.