Is it possible to make AGS read the text in a file during a game?[Solved]

Started by Icey, Fri 27/04/2012 23:30:23

Previous topic - Next topic

Icey

Like I want to have a universal save data for one of my games. This is due to the game having many updates and I don't wont the player to get mad cause they got to start all over. I want to make it were AGS loads the normal save data then searches for a Save#.tmp files and if it finds them it will check the files for it's Text.

Like if(such & such.text == "Player Level 12  Hp:1024  Mp:140"){
PlayerHp = 1024;
playerLv = 12;
PlayerMp = 140;

}

Hernald

Look up 'File Functions and Properties' in the manual; this will tell you how to read and write files at runtime.

Doing this will be unlikely to help you avoid the game crashing when a player tries to resume a game after you have made changes to the code, especially if you have added new variables. Can you be absolutely sure that you won't want to change what information you include in these files?

The example you give of how this file would be used is not going to work; Using 'if' statements in this way would mean you would have to code for every possible permutation of variables that you might be reading. Better to read in a number of integers and have them update globals. Better still, use the standard game saves and test your game properly before visiting it on players.


Icey

Ok, I have a plan B. It's easy but people might use it to cheat through the game....eh, what ever. Thanks though.

Lt. Smash

This shouldn't be too difficult.

First write the tmp-file. Remember in which order you write the different data.
Code: ags

File *file = File.Open(String.Format("save%d.tmp", current_savegame_nr), eFileWrite);
if (file != null) {
  file.WriteInt(current_lvl);
  file.WriteInt(current_hp);
  file.WriteInt(current_mp);
  file.Close();
}

In the same order you read the data:
Code: ags

File *file = File.Open(String.Format("save%d.tmp", current_savegame_nr), eFileRead);
if (file != null) {
  current_lvl = file.ReadInt();
  current_hp = file.ReadInt();
  current_mp = file.ReadInt();
  file.Close();
}

I hope this gives you an idea...  ;)

Icey


SMF spam blocked by CleanTalk