Game remembers things after player has quit - how?

Started by Ginny, Thu 09/10/2003 20:14:51

Previous topic - Next topic

Ginny

If for example, I want a certain option on the main menu (a hotspot) to be activated when the player finishes the game (like the Extra's in TLJ), and I also want the game to remember the player has finished the game even after he has quit. I could of course try making the game auto-svae, but I don't want to have an extra save game in the list. Also, how do I autosave? Presumably the save game listbox shows only 20 slots, right? So do I save to slot 47 for example? Still, I'm not sure this is the best solution, or if it'll work at all.

All help is very much appreciated :)
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

Spyros

You can use the file function and write a text file just before the player finishes the game (you can only write a number in the text file  eg 123. Then when the player starts the game again read the file and see if the number 123 is in the file. If it is it means that the player has finished the game

Scorpiorus

#2
QuoteAlso, how do I autosave? Presumably the save game listbox shows only 20 slots, right? So do I save to slot 47 for example?
Yes, you  can call the SaveGameSlot () command:

//after player has finished the game

SaveGameSlot (47, "game finished");

and it won't be displayed in the standart save/load dialog

then as the player opens main menu (player enters screen before fade-in maybe)

string slotname;
//if slot exists...
if (GetSaveSlotDescription (47, slotname) == 1)
//..and and it's slot description correct
if (StrComp(slotname, "game finished")==0) {

EnableHotspot(3); //enable secret option

}



Another way is to create a separate file (as Spyros described) and hold all the info inside. It's almost the same as the autosave method but requires a little more amount of code. On the other hand the file size will be reduced to minimum:

player has finished the game:

//try to create file 'game.dat' to write data
int file = FileOpen ("game.dat", MODE_WRITE);
//if AGS can't create file (disk is full for example)
if (file == 0) {
Display("I/O error"); // diplay appropriate error
QuitGame(0); // and quit
}
//...else write a string to the file
FileWrite (file, "game finished");
//finally, close file
FileClose(file);



on menu load (before fade-in)

//try to open 'game.dat' file for reading data
int file = FileOpen("game.dat", MODE_READ);
//if file exists
if (file != 0) {
string buffer; // declare some buffer
FileRead (file, buffer); //read data to buffer
// check the read string to be correct
if (StrComp(buffer, "game finished")==0) {
EnableHotspot(3); //enable secret option
}
}


~Cheers


Ginny

Many thanks Spyros and Scorpious :) I had been trying to use an autosave but had made a strange error :P I added one bracket pair too many to the "if" statement. thanks :) I'll probably use the File I/O function (btw, what does I/O stand for?) after I dechiper the code ;)

Once again, thank you!
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

Scummbuddy

- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

Scorpiorus

#5
Quote from: GinnyW on Fri 10/10/2003 00:53:58
Many thanks Spyros and Scorpious :) I had been trying to use an autosave but had made a strange error :P I added one bracket pair too many to the "if" statement. thanks :)
Ah, get rid of the last bracket :):

string slotname;
//if slot exists...
if (GetSaveSlotDescription (47, slotname) == 1)
//..and and it's slot description correct
if (StrComp(slotname, "game finished")==0) {

EnableHotspot(3); //enable secret option

}
}

I also added comments for the second method.

~Cheers

Ginny

Great, thanks again, works perfectly :) And thanks to Scummbudy too ;)
Try Not to Breathe - coming sooner or later!

We may have years, we may have hours, but sooner or later, we push up flowers. - Membrillo, Grim Fandango coroner

SMF spam blocked by CleanTalk