Achievement Systems

Started by KodiakBehr, Sun 28/04/2013 05:49:38

Previous topic - Next topic

KodiakBehr

Hi there,

I'm looking to implement achievements for Conspirocracy (which has fallen to the 5th page of the coming soon boards!).  I assume the only way to do this is to have the game draw data from an "achievement" file upon every load.  How would I go about writing and loading information from this hypothetical file?

Is there a better (or more coherent) way of going about this?

Thanks!

KB

frenzykitty

Could you not create a bunch of booleans for each possible achievement, have them all set to 0 at the beginning of the game, and as the player unlocks them, set them to 1?

And then have an "Achievements Page" - a room with a bunch of objects - one for each achievement/badge and their visibility is off if their bool is 0? Just a bunch of if statements?

geork

I assume the issue is that restarting the game would reset the achievement variables (unless you meticulously reset every game related variable manually - which would be very time consuming). I would have to functions:
Code: AGS
void WriteAchievements(){ //Write achievement data to file
  File *i = File.Open("Achievements.dat",eFileWrite);
  i.Write(Var1); //where Var are your variables
  i.Write(Var2);
  i.Write(Var3);
  //etc etc
}
void ReadAchievements(){//Read Achievement data from file
  if (!File.Exists("Achievements.dat")) return; //if the file hasn't been created yet, exit the function
  File *i = File.Open("Achievements.dat",eFileRead);
  Var1 = i.ReadInt();
  Var2 = i.ReadInt();
  Var3 = i.ReadInt();
  //etc etc
}

Then, there are two points at which you need to call each. you need to call WriteAchievements() whenever the player quits the game, or when the game is about to restart (so just before you call QuitGame(0) or RestartGame())

There are two points you should call ReadAchievements() - that is in game_start() and on_event for when the game is restored. like:
Code: AGS
function game_start(){
  ReadAchievements();
}
function on_event(EventType Event, int data){
  if(Event == eEventRestoreGame){ //After a reload
    ReadAchievements()
  }
}

(all this has sort of been tested, but a long time ago)

Hope that helps :)

KodiakBehr

Very helpful!  I will experiment and get back to you.

frenzykitty

would the variables only be reset when the player starts a new game? i.e. if they load a game will the variables that have been changed during that playthrough save state? (sorry for jumping in with a question of my own :-) )

Khris

What AGS does is always save the game state at the very beginning using slot 999.
When you start a new game / reset the game using the built-in command, AGS simply loads that save state, so all variables are automatically reset to their initial values.
And of course, every variable gets included in save games, otherwise what's the point.

Thus, if you want to keep track of data regardless of game state/progression (as in achievements), you have to save the variables yourself, in an external file.

frenzykitty


KodiakBehr

The code worked brilliantly.  Thank you very much geork.

SMF spam blocked by CleanTalk