Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: alisa_tana on Fri 19/06/2009 05:25:13

Title: Saving only variables?[solved]
Post by: alisa_tana on Fri 19/06/2009 05:25:13
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!
Title: Re: Saving only variables?
Post by: Gilbert on Fri 19/06/2009 06:04:19
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 (http://www.adventuregamestudio.co.uk/manual/File%20functions%20and%20properties.htm). 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.
Title: Re: Saving only variables?
Post by: monkey0506 on Fri 19/06/2009 06:07:55
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:

// 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 (http://www.adventuregamestudio.co.uk/manual/File%20functions%20and%20properties.htm) 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 (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27385.0) 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.
Title: Re: Saving only variables?
Post by: alisa_tana on Fri 19/06/2009 18:18:23
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!
Title: Re: Saving only variables?
Post by: alisa_tana on Mon 22/06/2009 07:32:29
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?
Title: Re: Saving only variables?
Post by: Gilbert on Mon 22/06/2009 07:40:07
You may use a while loop to do so. Something like:

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

and

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.
Title: Re: Saving only variables?
Post by: alisa_tana on Mon 22/06/2009 07:51:31
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.