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.
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?
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 ^^
You could convert the value to a string and save it in the save slot description when using the SaveGameSlot function.
Interesting. It would definitly work that way. Thanks.
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.
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.
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
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.
Thank you very much strazer.
Another idea is to make another file that stores this information, when saving a game, such as a small .txt file.