Game Attributes - Possibility to choose if they get saved by "save game"

nev

  • *
  • Posts: 386
Sometimes it can be useful to have global attributes which don't get saved along when the "save game" block is executed. I found this old post on the topic:
http://community.stencyl.com/index.php?topic=190.msg44923
Is there some news on this front? If not, then I'm asking for the following feature:

In the list of Game Attributes, put a check box for each attribute, to have the possibility to toggle between "saved by 'save game'" and "not saved by 'save game'".

Thanks!
Nev

Jon-iPad

  • *
  • Posts: 166
We actually used to have this toggle before. I don't recall why we yanked it.

Joe

  • *
  • Posts: 2480
We actually used to have this toggle before. I don't recall why we yanked it.

Hmm, we did? I don't recall that.

coleislazy

  • *
  • Posts: 2607
A quick work-around would be to have a behavior set the particular attributes you don't want saved to a "default" value whenever the game is loaded.

camaleonyco

  • Posts: 204
A quick work-around would be to have a behavior set the particular attributes you don't want saved to a "default" value whenever the game is loaded.
How can I do that? As far as I know you cannot "clear" a game attribute. If I set a number attribute to "0", does it really lower the size of the Shared Object? Right now I'm getting Local Storage warnings, and this feature will help a lot to avoid that.

coleislazy

  • *
  • Posts: 2607
Ah, in that case, no. All game attributes are saved when you invoke a save. However, since its all AS3 under-the-hood, you can avoid using the save block and instead code a save feature like you would a "normal" AS3 project.

camaleonyco

  • Posts: 204
Ah, in that case, no. All game attributes are saved when you invoke a save. However, since its all AS3 under-the-hood, you can avoid using the save block and instead code a save feature like you would a "normal" AS3 project.

So, are you suggesting to create our own shared objects to avoid saving useless data? I guess that will not be as easy as it sounds, but maybe I will give it a try. So just to be sure, I would have to create the Shared Object at the first scene's behavior:

Code: [Select]
var mySO:SharedObject = SharedObject.getLocal("myGameSO");
Since the scene behavior already imports "flash.net.*" I won't need to import "flash.net.SharedObject", right?

To set some default values I will need to add:

Code: [Select]
if (mySO.data.Scores==undefined) {
mySO.data.Scores = [0,0,0,0,0];
mySO.data.Muted = false;
}

And translate that data to game attributes:

Code: [Select]
setGameAttribute("Score", mySO.data.Scores);
setGameAttribute("Muted", mySO.data.Muted);

Then, each time I want to save a game attribute, I will need to add a code block, inside a "Flash Only" block:

Code: [Select]
mySO.data.Scores = getGameAttribute("Scores") as Array;
mySO.flush();

Or I could check if the data has been flushed (I'm not sure if this would work, since I have never used SharedObjectFlushStatus):

Code: [Select]
if (mySO.flush() == SharedObjectFlushStatus.FLUSHED){
_savedGame = true; //where savedGame is a local attribute
}

And I can keep my save and load blocks inside "iOS only" blocks... Is that it, or I need to do something else?

However, it still will be a great idea to add a checkbox for attributes you want to save, since we sometimes will need a lot of global variables, that we don't want to be considered as Shared Object data... because we don't want to annoy players with those suspicious Local Storage warnings.


camaleonyco

  • Posts: 204
Quote
So, are you suggesting to create our own shared objects to avoid saving useless data? I guess that will not be as easy as it sounds...
Wow! That was as easy as it sounded! Now I can use all the game attributes I want... unless iOS has a tight storage limit too, but I guess I won't use that many game attributes. Does anyone knows what is the limit for Local Storage for iOS games?

Anyway, since Jon hasn't commented this suggestion I guess we won't see this feature in the near future, in the meantime I will use that custom Shared Object.

coleislazy

  • *
  • Posts: 2607
It is a good idea. Jon is a busy man, so a lack of comment on an idea doesn't always mean it will be forgotten.

I'm glad you were able to get this working! I've never saved anything in Flash without using Stencyl, so I had no idea how to do it!

mikhog

  • Posts: 151
Thanks so much for this solution, camaleonyco!

It solved my save problem as described in http://community.stencyl.com/index.php/topic,28074.new.html#new
so it's useful for handling a save game bug too.
"It came from the forest!" a zombie defense shooter
http://www.kongregate.com/games/mikhog/it-came-from-the-forest
Also, check out my RPG inventory system on stencyl forge or test it: http://www.stencyl.com/game/play/25268
Current project (hack n slash RPG): http://www.stencyl.com/game/play/25366
I also do Unity development both 2D and 3D

mikhog

  • Posts: 151
How would this be done in Stencyl 3.0? Can you access LSO:s in 3.0 or would you need to write an extension for that?
"It came from the forest!" a zombie defense shooter
http://www.kongregate.com/games/mikhog/it-came-from-the-forest
Also, check out my RPG inventory system on stencyl forge or test it: http://www.stencyl.com/game/play/25268
Current project (hack n slash RPG): http://www.stencyl.com/game/play/25366
I also do Unity development both 2D and 3D