[SOLVED] Saving game before changing room

Started by Laura Hunt, Thu 28/05/2020 18:22:07

Previous topic - Next topic

Laura Hunt

Quote from: Khris on Fri 29/05/2020 09:10:30
Here's a minimal example:

Beautiful. Thanks, Khris. It all clicks now.

Quote from: Khris on Fri 29/05/2020 09:10:30
The manual says:
QuoteThe function doesn't get called immediately; instead, the engine will run it in due course, probably during the next game loop, so you can't use any values set by it immediately.

However, to reiterate: the same thing can be achieved by simply using SetTimer() with a delay of 1.

Yeah the part where it says "probably during the next game loop" is hilarious. Probably. Maybe. Maybe not. Who knows, lol. But yeah, if it runs in the next game loop, then there's no advantage to this over setting a timer, as CW would still be paranoid that something could be pressed in that one cycle :-D

Thanks a lot again. This thread is teaching me SO much.

Snarky

Seems like you got it while I was writing, but since I already wrote it…

Quote from: Laura Hunt on Fri 29/05/2020 09:08:07
ok waitwaitwait I think I got it.

I assume You use RESTART_GAME instead of simply passing an int value directly, in order to make things more readable and not have to memorize what custom event each value refers to.

Correct.

Quote from: Laura Hunt on Fri 29/05/2020 09:08:07If you want to have different stuff happening, you can create an enum assigning int values to names that make it easier to remember what you're doing (e.g., instead of having to remember that 0 in this context means "restart game", I assign the value 0 to RESTART_GAME).

Yes, and I would use an enum rather than constants to ensure each value is unique. (I might also skip 0 just because that's often a "default" value that could conceivably be called by mistakeâ€"though with an enum that isn't a concern since AGS enums start from 1.)

Quote from: Laura Hunt on Fri 29/05/2020 09:08:07Another thing that was confusing me a bunch was if (RESTART_GAME == script), but this is just the same as if (script == RESTART_GAME), right? You're just comparing both sides of an equation. It felt super counterintuitive to see it written "the other way around".

I agree that it's counterintuitive, but this (putting the known value first) is a somewhat common style. For object-type comparisons in languages where the == operator can be overridden, it ensures that you don't try to run null.Equals(), which would crash.

Quote from: Laura Hunt on Fri 29/05/2020 09:08:07And then do_your_thing() would actually be RestartGame();

Right.

Original answer:

Quote from: Laura Hunt on Fri 29/05/2020 08:52:28
I read that yesterday trying to grasp what fernewelten was talking about, but I still can't make heads or tails of it. The first thing that this entry says is "Calls the on_call function in the current room script" but there seems to be no entry or explanation in the manual for the "on_call" function and how it works.

The explanation for on_call() is that entry: you add a function like this to your room script:

Code: ags
function on_call(int value)
{
  // ...
}


And then CallRoomScript(x); means that this function in the current room will be called with the value x as parameter. So if call CallRoomScript(RESTART_GAME); that means that in on_call(), the value of value is set to RESTART_GAME.

QuoteIf RESTART_GAME is an int, where do you define it? What value do you assign to it? 0, 1, 5, 23675? What exactly are you comparing when you do if (RESTART_GAME == script)?

Well, first, script is just what fernewelten has decided to name the function argument instead of value like in the manual.

You can define the constant in several places, but probably the easiest is to do so in the Globalscript header. You could do it like so:

Code: ags
#define RESTART_GAME 1


The number doesn't really matter, the only thing that matters is that if you use CallRoomScript/on_call for different things, you need to use different numbers, so that you can distinguish it in on_call().

Laura Hunt

Quote from: Snarky on Fri 29/05/2020 09:22:11
You can define the constant in several places, but probably the easiest is to do so in the Globalscript header. You could do it like so:

Code: ags
#define RESTART_GAME 1


The number doesn't really matter, the only thing that matters is that if you use CallRoomScript/on_call for different things, you need to use different numbers, so that you can distinguish it in on_call().

Yup, all clear! God, I love this "a-ha!" feeling when everything just clicks. It's like taking mushrooms and suddenly understanding everything, but cheaper.

Crimson Wizard

#23
on_call is missing a proper entry in the manual, it's only mentioned in CallRoomScript entry afaik.

Also, there's a bunch of obscure things in AGS that I am not aware about... for instance searching for on_call in the manual, I found game.roomscript_finished variable, which means that "The on_call function has completed executing." ...

Cassiebsg

Uhm...
I normally just save my restore point after the intro... never had to do all that before.  (roll)
There are those who believe that life here began out there...

Crimson Wizard

#25
Quote from: Cassiebsg on Fri 29/05/2020 21:21:51
I normally just save my restore point after the intro... never had to do all that before.  (roll)

The problem was that if you restore that point, all in-game option changes made by player during this game session will be lost. It does not matter where the restore point is.

Cassiebsg

Yes, that I know.
I was just referring to this post "https://www.adventuregamestudio.co.uk/forums/index.php?topic=58129.msg636621247#msg636621247" ...
QuoteWhat I actually need is to restart the game in order to revert everything to its initial state.

However, this would make the intro play again instead of going straight to the main menu, so what I've done is:

Saving the settings is a 3rd problem that come after.  ;)
There are those who believe that life here began out there...

Crimson Wizard

Quote from: Cassiebsg on Fri 29/05/2020 22:19:01
Yes, that I know.
I was just referring to this post "https://www.adventuregamestudio.co.uk/forums/index.php?topic=58129.msg636621247#msg636621247" ...
QuoteWhat I actually need is to restart the game in order to revert everything to its initial state.

However, this would make the intro play again instead of going straight to the main menu, so what I've done is:

Saving the settings is a 3rd problem that come after.  ;)

Now I understand. But that post is like 15 or 20 comments above in the middle of the previous page, and no one was discussing it since, so I won't be able to know without explanation or a quote

Laura Hunt

Quote from: Cassiebsg on Fri 29/05/2020 21:21:51
Uhm...
I normally just save my restore point after the intro... never had to do all that before.  (roll)

Right. The issue is that I might (not 100% sure yet) want to start the main menu music before the intro so that it starts playing while the intro is running, so putting the restore point after that wouldn't work for me :)

SMF spam blocked by CleanTalk