Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kikutaâ„¢ on Tue 03/05/2005 22:05:13

Title: Getting a var from saved game.
Post by: Kikutaâ„¢ on Tue 03/05/2005 22:05:13
Hello!

I would like to know if there is any possible way to get a value from an int var used in a saved game.

I want that because I need to get the time played in a saved game (the time is stored in tempo_jogado var) , to be displayed when the game starts (before loading the saved game).

Thank you.
Title: Re: Getting a var from saved game.
Post by: Rui 'Trovatore' Pires on Tue 03/05/2005 22:08:31
Hmmmm... not directly, but if you dabble in AGS' file system, you might be able to do what you want. Stuff like, when the pplayer SAVES you do 3 things: You SAVE, you WRITE IN A FILE THE SAVE SLOT and you WRITE IN A FILE THE TIME.

Then what you do is read and display the TIME of the SAVE SLOT in question.

Or something. DOes this make sense? Or sound workable?
Title: Re: Getting a var from saved game.
Post by: Kikutaâ„¢ on Tue 03/05/2005 22:17:15
Excelent idea! I never though of that. But there is one problem. The var would be accessible to everyone. Picture this, a child takes over a pc (from his brother) acidently opens the file and write random stuff in it :P

I would rather access it within the game, that writting in a file. But that's for your idea. It's workable ^^
Title: Re: Getting a var from saved game.
Post by: strazer on Tue 03/05/2005 23:04:32
You could convert the value to a string and save it in the save slot description when using the SaveGameSlot function.
Title: Re: Getting a var from saved game.
Post by: Kikutaâ„¢ on Tue 03/05/2005 23:21:01
Interesting. It would definitly work that way. Thanks.
Title: Re: Getting a var from saved game.
Post by: Rui 'Trovatore' Pires on Wed 04/05/2005 06:32:28
Out of curiosity, I thought that when we wrote something in a file via AGS, AGS "crypted" it so that when we opened the file it seemed like so much random mumbo-jumbo. Does it behave like this? Or do we really see the actual strings and numbers when we open the file? And why in the heck am I too lazy to try it out myself? How I wonder.
Title: Re: Getting a var from saved game.
Post by: Gilbert on Wed 04/05/2005 06:51:45
Not if you really know the file formats. And for binary or data files you created in a game they're obviously not cyphered, you can do it yourself though.

Cyphering of strings in compiled was not implemented until V2.61.
QuoteEncrypted strings in compiled files, to prevent the player loading the exe into notepad to cheat.

Spoiler
However, up till now I think not all data are cyphered, you may still view some of the strings, like dialog texts, for example to cheat in games.
[close]
Title: Re: Getting a var from saved game.
Post by: Kikutaâ„¢ on Wed 04/05/2005 11:03:31
Yep. They are not crypted. But i did one thing. I've made a file that is called Data.dlc. This is a regular txt file , but with a different extension. I won't be crypting it. It would be a perfectly wast of  time :P
Title: Re: Getting a var from saved game.
Post by: strazer on Wed 04/05/2005 18:02:02
If you're still interested in storing/retrieving variables from save slots, here is a way to do it:


// global script

//...

function myGetArgument(string source, int argumentno, string destination) {

  StrCopy(destination, ""); // initialize argument string

  short foundarguments;
  short charposition;
  while (charposition <= StrLen(source)) { // loop until end of source string

    char letter = StrGetCharAt(source, charposition); // get letter from source string

    if ((letter == '/') || (letter == 0)) { // if end of argument reached
      foundarguments++; // increase number of found arguments
      if (foundarguments == argumentno) return 1; // if desired argument found, return success and quit function
      else if (letter == 0) { // if desired argument NOT found
        StrCopy(destination, source); // return whole source string as argument (for example)
        return 0; // return failure and quit function
      }
      else StrCopy(destination, ""); // continue with next argument
    }
    else StrFormat(destination, "%s%c", destination, letter); // if end of argument NOT reached, append letter

    charposition++; // loop to next letter
  }

}

//...



// main script header

//...

import function myGetArgument(string source, int argumentno, string destination);

//...


To save data (example):


  //...

  string buffer;
  StrFormat(buffer, "%s/%d/%d", "Warehouse", timeplayed, score); // arguments must be seperated by a /
  SaveGameSlot(SAVESLOTNUMBER, buffer);

  //...


To retrieve data (example):


  //...

  string buffer;
  GetSaveSlotDescription(SAVESLOTNUMBER, buffer); // get save slot description

  string argument;

  myGetArgument(buffer, 1, argument); // get first argument from save slot description
  string saveslotname;
  StrCopy(saveslotname, argument);

  myGetArgument(buffer, 2, argument); // get second argument from save slot description
  int timeplayed = StringToInt(argument);

  myGetArgument(buffer, 3, argument); // get third argument from save slot description
  int score = StringToInt(argument);

  //...


Keep in mind you can only save up to 200 letters per save slot description.
Title: Re: Getting a var from saved game.
Post by: Kikutaâ„¢ on Wed 04/05/2005 18:54:59
Thank you very much strazer.
Title: Re: Getting a var from saved game.
Post by: simulacra on Wed 04/05/2005 19:23:25
Another idea is to make another file that stores this information, when saving a game, such as a small .txt file.