Saving attribute/image when switching scenes
CrumbyEntertainment
Member, PRO Posts: 32
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.
Note: i made a game attribute called FavoriteButton and use that for the basis of changing my image.
Comments
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.
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
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!
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.