Saving only variables?[solved]

Started by alisa_tana, Fri 19/06/2009 05:25:13

Previous topic - Next topic

alisa_tana

I'm not sure if this is more complicated than for a beginner or not, but I still consider myself as being a beginner...

I know that the save game function saves just about everything to the save file, variables, sprite views, room and location...
But I only need to write the variables to the save file, can this be done?

Reason being, I'm making a fighting/platformer game ( http://www.alisachristopher.us/avatarsd ) and I only want to save which data has been unlocked, the player score, and options that the player has set (like key choices, and match settings).



(secondary question, any idea if and when custom properties will become more than readonly?)

Thanks!

Gilbert

Just save the variables to a binary file, in whatever formating you want. In my (yet unreleased) game I never use the engine's savegame feature, I use the file functions to save game config, level layouts, high scores, etc. Just check them out. I think there may be a module or two that would aid you in writing formated files, but as I never find a need to use them I never checked.

monkey0506

This is a somewhat techy question, but it could fairly easily go either way...

Now it's a little unclear exactly what you are/are not wanting to be saved. One possibility would be for you to do something like:

Code: ags
// save data
SaveGameSlot(998, ""); // save file to store the settings

// load data
RestoreGameSlot(998);

// GlobalScript.asc
function on_event(EventType event, int data) {
  if (event == eEventRestoreGame) {
    if (data == 998) { // load settings
      player.ChangeRoom(1, START_X, START_Y);
      // optional, reset player's inventory
      int i = 0;
      while (i < Game.InventoryItemCount) {
        player.InventoryQuantity[i] = 0;
        i++;
      }
      UpdateInventory();
    }
  }
}


I'm not sure what all settings you're looking to keep and what you want to lose...so...that should maybe give you an idea.

Another thought is to use the File functions to save the settings either (as plain-text) with the Raw functions or (non-human-readable, but still AGS-readable) encrypted with WriteInt and WriteString.

As far as the question about when custom properties will become readable, I don't think there's an official answer to that yet. However, the Properties module is designed to allow for custom, run-time editable properties. If you're going to use it, IIRC you will need to edit the Properties.ash file and set eProperties_MaxRooms and eProperties_MaxProperties to sufficiently high values or you'll end up crashing it. I think for some reason in the release I had them set to something silly like 1. ::) I should really look into updating that to work off of my Stack/String-vector technology anyway.

alisa_tana

Ah, Thanks.  The file functions worked great (once I figured 'em out)  since I only have a handful of variables that need to be recorded.

I'll try out that properties module too.

Thanks!

alisa_tana

Related question to using the File functions....

I've got two arrays that need to be saved.

I know with the standard integers I just use
output.WriteInt(blah);  and
blah = input.ReadInt();

But what do I do for my arrays short of making a separate line for each index in the array?

Gilbert

You may use a while loop to do so. Something like:
Code: ags

int i=0;
while (i<10){
  output.WriteInt(blah[i]); 
  i++;
}

and
Code: ags

int i=0;
while (i<10){
  blah[i]=input.ReadInt();
  i++;
}


Make sure that you manage the "format" of the data file well yourself. As long as you're clear what order and quantity the variables are written to a file and read them in the same manner everything should be fine.

alisa_tana

Sweet, thanks.  I had a feeling it would be something similar to that, but I just fall short when it comes to syntax sometimes.  thus why I'm still a beginner.

SMF spam blocked by CleanTalk