Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Darius Poyer on Thu 02/02/2012 11:58:24

Title: Saving data outside of gamesaves.
Post by: Darius Poyer on Thu 02/02/2012 11:58:24
Hello there,

I am working on a game, it will feature permadeath but still some save function so you can leave and continue your game. I would like to somehow store data beyond the actual gamesaves like total time played, deaths and how you died etc.

I suppose I could get a bit clever with autosaves and autoload something on start, but it seems messy. I also thought about saving to a text file and reading the lines back but that to seems like a bad solution. what can I do?
Title: Re: Saving data outside of gamesaves.
Post by: suicidal pencil on Thu 02/02/2012 12:39:41
actually, saving the data to a text file and reading it back in when you need it is not a bad solution, and probably the only way to save data not saved by AGS.
Title: Re: Saving data outside of gamesaves.
Post by: cat on Thu 02/02/2012 12:43:39
You could also encrypt the textfile or add a checksum to avoid that players might edit it.
Title: Re: Saving data outside of gamesaves.
Post by: on Thu 02/02/2012 13:13:25
Yuup, create a file and write your data to it. You must make sure the game can find your file: in Vista, for example, you can't acess the game's folder when the user installed it in Program Files. The manual suggests to always write to the Save Game Folder with a special tag:


File *output = File.Open("$SAVEGAMEDIR$/temp.tmp", eFileWrite);
if (output == null)
  Display("Error opening file.");
else {
  output.WriteString("test string");
  output.Close();
}


You can read and write strings and integer values, and in combination with structs it's not too hard to create a custom save/load system. You TOTALLY lose the comfort of AGS's interal save/load stuff, however- like player positions, the value of sound and music sliders, and even if objects have been turned on or off.
Depending on WHAT you want to save, you may need to make sure the game updates its data depending on stuff saved in your file.

If you just want to keep trackof games played and the like, however, it's pretty simple.
Title: Re: Saving data outside of gamesaves.
Post by: Creator on Thu 02/02/2012 13:38:34
Quote from: cat on Thu 02/02/2012 12:43:39
You could also encrypt the textfile or add a checksum to avoid that players might edit it.

I'm thinking about doing something similar as the OP and I'm pretty sure I can do reading and writing to a file, but how could I go about doing this?
Title: Re: Saving data outside of gamesaves.
Post by: on Thu 02/02/2012 14:04:55
Quote from: Creator on Thu 02/02/2012 13:38:34
I'm thinking about doing something similar as the OP and I'm pretty sure I can do reading and writing to a file, but how could I go about doing this?

There's a module for that- I have not tried it out myself and it's pretty old, but maybe it's useful:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23109.0
Title: Re: Saving data outside of gamesaves.
Post by: Darius Poyer on Thu 02/02/2012 14:53:50
Quote from: Ghost on Thu 02/02/2012 13:13:25
Yuup, create a file and write your data to it. You must make sure the game can find your file: in Vista, for example, you can't acess the game's folder when the user installed it in Program Files. The manual suggests to always write to the Save Game Folder with a special tag:


File *output = File.Open("$SAVEGAMEDIR$/temp.tmp", eFileWrite);
if (output == null)
  Display("Error opening file.");
else {
  output.WriteString("test string");
  output.Close();
}


You can read and write strings and integer values, and in combination with structs it's not too hard to create a custom save/load system. You TOTALLY lose the comfort of AGS's interal save/load stuff, however- like player positions, the value of sound and music sliders, and even if objects have been turned on or off.
Depending on WHAT you want to save, you may need to make sure the game updates its data depending on stuff saved in your file.

If you just want to keep trackof games played and the like, however, it's pretty simple.


Is there anything I should be aware of in terms of file extensions, does it even matter unless I use something already established?
I mean, I suppose that the extensions could be anything at all really. I recall the game vvvvvvv having the extension *.vvvvvv for example.
Or is there something special about the *.tmp format?
Title: Re: Saving data outside of gamesaves.
Post by: Creator on Thu 02/02/2012 15:12:43
Quote from: Ghost on Thu 02/02/2012 14:04:55
Quote from: Creator on Thu 02/02/2012 13:38:34
I'm thinking about doing something similar as the OP and I'm pretty sure I can do reading and writing to a file, but how could I go about doing this?

There's a module for that- I have not tried it out myself and it's pretty old, but maybe it's useful:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=23109.0

Thanks, Ghost. I'll check that out.
Title: Re: Saving data outside of gamesaves.
Post by: on Thu 02/02/2012 15:52:27
Quote from: Darius Poyer on Thu 02/02/2012 14:53:50
Is there anything I should be aware of in terms of file extensions, does it even matter unless I use something already established?
I mean, I suppose that the extensions could be anything at all really. I recall the game vvvvvvv having the extension *.vvvvvv for example.
Or is there something special about the *.tmp format?

You can use anything, really. If you chose an already registered extension, users who try to open the file will have it opened with the registered program, though, but that's all. DAT is popular, but as far as AGS is concerned, the extension is just part of the name, and it doesn't affect the file at all. You can have extensions longer than three letters too, but I do not know the upper limit (or if there is any).
Personally I go with either DAT or CSF ("Custom Save File"). Never broke anything.
Title: Re: Saving data outside of gamesaves.
Post by: cat on Fri 13/12/2019 15:24:31
A search for "store data file" brought up this thread and I thought I could just reuse it with an additional question:

I am now considering to use this solution for my game. The only concern is: Would writing a file cause problems on Android? It is important for me that the game still runs fine on my mobile phone.
Title: Re: Saving data outside of gamesaves.
Post by: Crimson Wizard on Fri 13/12/2019 18:12:42
Quote from: cat on Fri 13/12/2019 15:24:31
A search for "store data file" brought up this thread and I thought I could just reuse it with an additional question:

I am now considering to use this solution for my game. The only concern is: Would writing a file cause problems on Android? It is important for me that the game still runs fine on my mobile phone.

AGS can definitely write files on Android, otherwise it won't be able to save games.  I don't remember testing script file commands though, but hope they are okay, because it's essentially same thing.
I also don't remember where $APPDATADIR$ points to (could be game directory itself).