Remember/store value outside of load/save routine? [Solved]

Started by BrightBulb, Fri 09/03/2012 22:33:40

Previous topic - Next topic

BrightBulb

Hello everybody,

I'm making a simple graphic adventure and came across a problem implementing a score system.

For doing stuff you get points and your score increases. Now, when you get stuck in the game you can ask your sidekick for advice, but this imposes a score penalty. So when you beat the game without any help, your score is higher.

Now it's fairly easy for a player to avoid this penalty by saving the game, ask for advice and restore the game. I wanted to prevent that. So the goal is for the penalty to stay effective even after a reload.

My first try was to save the currentscore in an external file using read/write int. But the problem with this is that a player gains and loses points twice when playing the same situation twice. For example, player asks for advice and gains -10 points for a total of -10 points, these points are saved, so that even after a reload his score is -10. But if he asks for the same advice again he will gain another -10 points.

Anybody with some ideas?


Khris

What you have to do is not just store the current points in the file but a list of the hints, which each entry reflecting whether it has been used or not.

If you want multiple people to be able to play the game on one machine, have the player enter a profile name when starting a new game, and use that to identify which external file belongs to which savegame. (Or do it internally by checking existing files and using the next free number or something like that.)

Each time the player uses a hint, the file is updated by marking the hint as used. After a game is restored, AGS reads the hint file to find out which ones were already used. That way, the player can't cheat by restoring a game after reading a hint.
Since your game can now keep track of which hint has been used independent of savegames, it's easy to calculate the points.

As for the scripting side, a simple encryption and File.Read/WriteRawChar should suffice.
The hints have to be numbered and all you need to store is binary data, 0 for not used yet, 1 for already used.

BrightBulb

I have never worked with the file commands before and read about it in the manual, but I have a question:

How do I write several integers to one file?
Would this work?
    
File *savefile = File.Open("$SAVEGAMEDIR$/savefile.tmp", eFileWrite);
    if (savefile == null)
    Display("Error opening file.");
    else {   
    
     int maxsavegames=99, counter=0; 
     while (counter<maxsavegames) {
      savefile.WriteInt(gamedata[counter].score);
      counter++;
     }    
      savefile.Close();
    }

Khris

Yeah, that's basically how you'd do it.

Two small things:
-the loop is supposed to iterate through all hints, not savegames (no technical error, I was just wondering about the name you used)
-it's not necessary to store  the hint's score penalty in the file, you just need to store whether the hint has been used or not

BrightBulb

I can't implement the advices right now, because they (naturally) depend on the puzzles which aren't ready yet. So I had to postpone that. But (I think) I understood your solution.

The script I posted was from another part of the project (but with similar problems) which saves additional savegame informations (such as date of the savegame) into an external files.

SMF spam blocked by CleanTalk