Tracking variables between games

Started by newwaveburritos, Tue 15/06/2021 00:28:51

Previous topic - Next topic

newwaveburritos

Initially, I wanted to release Kola Queen as one long game but the more I think about it the more I like the idea of releasing it as a series of shorter games so people can play them while I work on them and maybe even build a little excitement along the way.

I've gotten the file system working so it will track a variable between play sessions like a save game and it should also work between games provided I use the same save game directory for all of them.

What I want to happen is to have an import system much like the Quest for Glory games where you import a character.  Essentially, this will just import about ten different variables not fundamentally different than the stats used in QfG.  These variables are set by decisions you have made and friendships you have built along the way which I would like to track game to game.  So, I can make it work but I can't make it work where I record all of the variables into a single file which seems absolutely best.  The problem is I'm essentially just copying and pasting code from the manual into the game without really understanding how it works.  How do I save all of these variables into a single file so that these global variables can be set all at once and keep everybody's hard drives clean?

Here's the code, which fires when a button is pushed right now:

Code: ags
  File *output = File.Open("$SAVEGAMEDIR$/importvariables.tmp", eFileWrite);
if (output == null)
  Display("Error opening file.");
else {
  output.WriteInt(WhichQuestYouAreOn);
  output.Close();
}


This is what loads the variable:

Code: ags
File *input = File.Open("$SAVEGAMEDIR$/importvariables.tmp", eFileRead);
WhichQuestYouAreOn = input.ReadInt();

input.Close();

Khris

Is it going to be a bunch of ints? If so, just call  output.WriteInt(someVariable);  multiple times before closing the file.
In the new game, use  someVariable = input.ReadInt();  a bunch of times, in the same order.

newwaveburritos

Hey, thanks for the quick reply!  I do have some bools but those can be stored easily enough as ints.  I shouldn't need any strings though if that's what you mean.

SMF spam blocked by CleanTalk