Author Topic: Static vars separate from save games?  (Read 488 times)  Share 

MurrayL

    • I can help with AGS tutoring
    •  
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Static vars separate from save games?
« on: 13 Jul 2012, 12:57 »
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.
« Last Edit: 13 Jul 2012, 12:59 by MurrayL »

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: Static vars separate from save games?
« Reply #1 on: 13 Jul 2012, 13:07 »
Will saving custom file work for you?
Check File routines in the manual:
http://www.adventuregamestudio.co.uk/wiki/?title=File_functions_and_properties

MurrayL

    • I can help with AGS tutoring
    •  
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: Static vars separate from save games?
« Reply #2 on: 13 Jul 2012, 13:20 »
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: Adventure Game Studio
  1. int number;
  2. File *input = File.Open("stats.dat", eFileRead);
  3. number = input.ReadInt();
  4. 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

  • AGS Project Admins
  • Long live King Cat!
    • I can help with AGS tutoring
    •  
    • I can help with voice acting
    •  
  • Calin Leafshade worked on a game that was nominated for an AGS Award!Calin Leafshade worked on a game that won an AGS Award!
Re: Static vars separate from save games?
« Reply #3 on: 13 Jul 2012, 13:28 »
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.

Leon: You need the sword first before you can get the monkey.

MurrayL

    • I can help with AGS tutoring
    •  
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: Static vars separate from save games?
« Reply #4 on: 13 Jul 2012, 13:36 »
So it reads linearly?

For example:
Code: Adventure Game Studio
  1. var1 = 43;
  2. var2 = 63;
  3. var3 = 12;
  4.  
  5. WriteInt(var1);
  6. WriteInt(var2);
  7. 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: Adventure Game Studio
  1. var1 = ReadInt(); //43
  2. var2 = ReadInt(); //63
  3. 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.
« Last Edit: 13 Jul 2012, 13:39 by MurrayL »

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: Static vars separate from save games?
« Reply #5 on: 13 Jul 2012, 13:39 »
So it reads linearly?

For example:
Code: Adventure Game Studio
  1. WriteInt(43);
  2. WriteInt(63);
  3. 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

    • I can help with AGS tutoring
    •  
    • I can help with backgrounds
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Re: Static vars separate from save games?
« Reply #6 on: 13 Jul 2012, 13:44 »
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: Text
  1. playerHealth = 100;
  2. enemyHealth = 75;
  3.  
  4. PlayerPrefs.SetInt("pHP",playerHealth);
  5. PlayerPrefs.SetInt("eHP",enemyHealth);
And then retrieve the values later by using:
Code: Text
  1. playerHealth = PlayerPrefs.GetInt("pHP");
  2. ...
« Last Edit: 13 Jul 2012, 14:22 by MurrayL »

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: Static vars separate from save games?
« Reply #7 on: 13 Jul 2012, 14:08 »
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.
« Last Edit: 13 Jul 2012, 14:16 by Crimson Wizard »