Exported ints and RestartGame

Started by Bernie, Fri 26/11/2004 02:25:36

Previous topic - Next topic

Bernie

I'm using several integers in my game (imported in script header, exported at the end of global script and defined at the top of the global script).  However, those values are not reset when I call RestartGame().
I wrote a ResetValues() function that sets all values to zero as a workaround, but I was wondering why those values don't reset themselves upon restart? Even setting them to zero in game_start didn't help.

strazer

I think by default the restart point is automatically set to the first room you enter in the game.
Try moving the variable reset code there or set a restart point in the game_start function.

Edwin Xie

Hmm, I used that as an advantage when I make my player die. You did what you should have done when you wanted to reset the values.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Rui 'Trovatore' Pires

QuoteI think by default the restart point is automatically set to the first room you enter in the game.

Nope. It's set to the first PLAYABLE room, i.e., if you start with a blocking command, such as AnimateEx or Wait, the automatic restart point will only be put on the first PLAYABLE room.

You'd have thought this would be documented, BTW.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Radiant

Huh? I thought RestartGame simply made a saved game at the first point where the player is allowed to do anything - so how come the values don't reset?

Bernie

#5
My game immediately started itself into a cutscene, so the restart point didn't have time to do its thing. I just added a timer thing so it's playable for a short bit before the cutscene, but it still doesn't work. Hmm... :)
I'll just use my reset thing then.

Pumaman

RestartGame is functionally identical to RestoreGame. The likeliest problem here is that the restart point is set incorrectly, as has been mentioned.

At what point do you change these values from 0? Is it likely that the restart point would be set after you've already changed them?

Bernie

The first room is a room with a hidden player character, I've set it up that you need to click to start the actual game for now. In that room, no value is set. In theory, AGS should place the restart point there.
In the next room, a cutscene starts which sets a value to 1 at the end of a dialog with dialog_request.
When I restart the game, the value stays 1. The cutscene requires the value to be 0 (I'm comparing to it in the 2nd room's before fade in script), otherwise it won't start.

Pumaman

In the first room, try something like this in Enters Screen After Fadein:

SaveGameSlot(800, "restart point");

then, for your Restart Game option, rather than using the RestartGame command, do this:

RestoreGameSlot(800);

see if that works any better.

Bernie

Hmm... tried it, didn't work. I used 'first time player enters' instead 'after fadein'.

Problem is, it doesn't reset any values for me at all, not even GlobalInts.
As a test, I always added 1 to a global value under 'after fadein' in a room further ahead. I compared to that GI in the first screen, and it would keep rising after restarting. This happens with normal restarting AND the save game thing.
It's like the values stay in the memory, or something.

So, uh... that's not normal, is it? :)

Radiant

Hm... on a related topic - is there an official feature that allows you to save a var beyond a restartgame command? (short of opening a temp file and storing it there). Because I could think of a way where that would be useful.

Also, (small feature request) int ReadConfigOption (string name), and WriteConfigOption (string name, int value). These could read or write a line in the game's config file (of course this can be done with the existing file functions, but it's neater this way)

Pumaman

Quote from: Bernie on Sat 27/11/2004 03:29:34
Problem is, it doesn't reset any values for me at all, not even GlobalInts.
As a test, I always added 1 to a global value under 'after fadein' in a room further ahead. I compared to that GI in the first screen, and it would keep rising after restarting. This happens with normal restarting AND the save game thing.
It's like the values stay in the memory, or something.

Can you post an example game? I just tried a quick test game and it all worked fine, and I can't imagine that such a serious bug would exist in AGS without anyone else spotting it.

QuoteHm... on a related topic - is there an official feature that allows you to save a var beyond a restartgame command? (short of opening a temp file and storing it there). Because I could think of a way where that would be useful.

No, this is not currently possible. The entire game state is restored.

QuoteAlso, (small feature request) int ReadConfigOption (string name), and WriteConfigOption (string name, int value). These could read or write a line in the game's config file (of course this can be done with the existing file functions, but it's neater this way)

Why would the game need to edit its config file? I can't see where this would be useful.

Rui 'Trovatore' Pires

QuoteI can't imagine that such a serious bug would exist in AGS without anyone else spotting it
Hang on. I do remember the author of "The Cube" seemed to have similar trouble with globalints... I think he even posted it in this board, can't remember the thread though.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Edwin Xie

Yeah, he had trouble with that old man, you can't get past him the second time even though you put the tire and the wastebin on him.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Bernie

Those are weird happenings, indeed! :)

Anyway, just to keep you up to date: I've sent CJ a PM with a link to my game source. I'm hoping it's no AGS error, and just something stupid I did...

Radiant

Quote from: Pumaman on Sat 27/11/2004 19:07:24
QuoteAlso, (small feature request) int ReadConfigOption (string name), and WriteConfigOption (string name, int value). These could read or write a line in the game's config file (of course this can be done with the existing file functions, but it's neater this way)
Why would the game need to edit its config file? I can't see where this would be useful.

It wouldn't need to edit it, but it may be nice to be able to add things to it.
For instance, a game could store its SetGameSpeed () setting in there, and automatically read it in when starting a new game.
Or you could make a command GUI that is displayed either on the left or the right, and that state is saved in the config file.
Or, if you did some kind of non-adventure game like Platformerius, you could use it for a high score table.
Or, for a Indiana Jones-styled game, it could be used for storing the Indy Quotient.

I realize that all of these can be done with regular file access functions, but esp. the former two are actually config options and it would make sense to place them in a config file.

Pumaman

Quote from: Bernie on Sat 27/11/2004 22:25:13
Those are weird happenings, indeed! :)

Anyway, just to keep you up to date: I've sent CJ a PM with a link to my game source. I'm hoping it's no AGS error, and just something stupid I did...

Thanks for sending that.

The reason for your problem is that you have this:

RestartGame();
NewRoom(1);

what's happening is that the NewRoom is actually overriding and cancelling out the RestartGame, so in fact all that's happening is that NewRoom(1) is being called. This is why nothing is being reset.

If you use the default F9 restart key, you'll notice that it does work, because that still just does the RestartGame command.

I agree that this behaviour is a little strange and the engine should give some sort of error rather than just allowing this to happen. I'll look into a fix.

To fix your problem though, just remove the NewRoom command -- or better still, add "return;" after RestartGame().

QuoteIt wouldn't need to edit it, but it may be nice to be able to add things to it.
For instance, a game could store its SetGameSpeed () setting in there, and automatically read it in when starting a new game.
Or you could make a command GUI that is displayed either on the left or the right, and that state is saved in the config file.

Yeah, I can see the uses for that. Would anyone else find this a useful feature?

Bernie

Ah, so it WAS something stupid I did, good! Thanks for helping me out. :)

QuoteYeah, I can see the uses for that. Would anyone else find this a useful feature?

My game is split into chapters, and it would be sweet if it were possible to globally store if a chapter has been finished, so it can be replayed without having to load. If I can do this with that feature, then yes, I'd definately find it useful.

Pumaman

That can be done easily enough with the standard File I/O functions; the proposed feature would just make it easier to use.

Bernie

I see... I better go and check them out then, thanks!

SMF spam blocked by CleanTalk