Static vars separate from save games?

Started by MurrayL, Fri 13/07/2012 12:57:49

Previous topic - Next topic

MurrayL

I'm aiming to integrate some achievement-style unlocks in an AGS game, but they need to be separate from game save files. I read in a different topic that static variables in AGS are persistent between game saves, but I doubt they are also persistent between launches of the game itself.

Is there any easy way to have a set of static, globally accessible variables (int and bool would suffice) which can be made persistent between save files and game launches?

As an example, a boolean which stores whether or not the player has ever unlocked DoorX in the game. Once it has been unlocked once in a playthrough, the variable is set to true. Even if the player quit the application, opened it up again and started a new game, the boolean would still show that they, at some point in the past, unlocked DoorX.


MurrayL

Quote from: Crimson Wizard on Fri 13/07/2012 13:07:01
Will saving custom file work for you?
Check File routines in the manual:
http://www.adventuregamestudio.co.uk/wiki/?title=File_functions_and_properties

It certainly looks like it could work, but I'm a little unsure about its flexibility.

The example given for File.ReadInt is:
Code: AGS
int number;
File *input = File.Open("stats.dat", eFileRead);
number = input.ReadInt();
input.Close();


There doesn't appear to be any control at all over the organisation of the storage - from the example given, I'm not even sure that you can read back more than one int, let alone a specific one.  ???

Calin Leafshade

You just read them back in the same order that you wrote them.

Alternatively you could write it all as a big string and parse it yourself as you read it back manually.

MurrayL

#4
So it reads linearly?

For example:
Code: AGS

var1 = 43;
var2 = 63;
var3 = 12;

WriteInt(var1);
WriteInt(var2);
WriteInt(var3);


This could be read back in with successive calls of ReadInt(), each one returning the next number in the sequence (43, 63, then, finally, 12)?

Code: AGS
var1 = ReadInt(); //43
var2 = ReadInt(); //63
var3 = ReadInt(); //12


If so then that will work for what I have in mind. It's not as intuitive as a key/value system (since it means I have to write the entire file again whenever I change a value), but it's workable.

Crimson Wizard

Quote from: MurrayL on Fri 13/07/2012 13:36:20
So it reads linearly?

For example:
Code: AGS
WriteInt(43);
WriteInt(63);
WriteInt(12);


This could be read back in with successive calls of ReadInt(), each one returning the next number in the sequence (43, 63, then, finally, 12)?
If so then that will work perfectly for what I have in mind. It's not as intuitive as a key/value system, but it's workable.
Wwwhat? :)
Ofcourse it will return in same order. And what do you mean it is not intuitive? It's how file storage work since early days of computers :)

MurrayL

#6
Quote from: Crimson Wizard on Fri 13/07/2012 13:39:29
Wwwhat? :)
Ofcourse it will return in same order. And what do you mean it is not intuitive? It's how file storage work since early days of computers :)

Sorry, I've updated my example to something a little more easily understandable (if you ignore the syntax errors and treat it as pseudocode) ;)

I just meant its not as intuitive as using a key/value system like, for instance, the Unity engine. In Unity you can do the following:
Code: "JS"
playerHealth = 100;
enemyHealth = 75;

PlayerPrefs.SetInt("pHP",playerHealth);
PlayerPrefs.SetInt("eHP",enemyHealth);

And then retrieve the values later by using:
Code: "JS"
playerHealth = PlayerPrefs.GetInt("pHP");
...

Crimson Wizard

#7
Well, I believe it is actually possible to write a module which will allow to read/write values in similar fashion (i.e. key/values).
I thought there was one already, but maybe I am mistaken.

EDIT:
Only one I could find is this IniFile module: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=22599.0
But I am afraid it was made for older version of AGS.

SMF spam blocked by CleanTalk