Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kumpel on Tue 27/10/2015 02:59:02

Title: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Tue 27/10/2015 02:59:02
So that's the problem: My room is shown but instead of starting with room_firstload the parser jumps to room_load, then firstload and after that room_load again. Visually it is shown through a forced fadeout/in after the firstload-function is done. But I want the game to just start immediately after firstload. I noticed this happens even if nothing is inside room_load.

I would like to know what is the reason for that and can I prevent the game from doing so?

Cheers
Kumpel
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Khris on Tue 27/10/2015 18:44:31
The chronological order is this:

-room is loaded but invisible

-"enters room before fade-in" event, default function name: room_Load() (intended to set up the room whenever it is entered, turn on/off objects, walkable areas, position characters, etc.)

-room fades in (unless room transition is set to instant) and is now visible

-if room wasn't visited before, "first time enters room" event, default function name: room_FirstLoad()

-"enters room after fade-in" event, default function name: room_AfterFadein() (here, do stuff that always happens but is visible to the player, like the character walking inwards from outside the screen or similar)

The last two might happen the other way around, not sure.

You cannot change this order, it is hardcoded.
What you describe sounds like you have entered room_Load next to the after fadein event, too. First, fix that. Then start rearranging your code according to the actual order.
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Tue 27/10/2015 23:11:03
Yes I did all that and I can't see any disruptions because of false arrangements of my code. If I do debug and let the game do a debug break at the first room_load command (positioning the player), the game stops as it should before the fade in and again after the firstload, showing me the game calls room_load twice, right?

Is the order of the functions in the room script relevant for this process of calling up a room's initial functions?

My order is:

1    room_Load
2    some custom function to play a cutscene in a later moment of the game
3         FirstLoad
4         AfterFadeIn


I don't know what you mean with

Quote"you have entered room_Load next to the after fadein event, too"
. I didn't call firstload in roomload or otherwise if that's what you suggest.
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Snarky on Tue 27/10/2015 23:36:17
Khris means that in the event panel (by the room properties), where you can set which functions run for various room events, you may have set room_Load() as the function for the "After Fadein" event.

When something is going wrong with things like this, it's useful to remember that it's not enough to look at the code, you also have to check that the events are set up correctly.
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Tue 27/10/2015 23:47:31
No. This order is correct too. So nobody of you guys had this problem before, that the game fades again after Firstload? Or is it just normal, that the game needs to call room_load again? That would be a real bummer for me but i could live with it.

I am gonna try to repeat it in a blank new room to see if the same thing will happen.
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Khris on Wed 28/10/2015 00:28:55
The order of the functions in the script does not determine in what order they're called, no. The only time when the order in the script matters is when function A calls function B; in that case A has to be further up than B.

Like I already explained, the game is not supposed to call room_Load twice. And even if it does, the game should not fade in a second time.

In your original post you state that not only is first_Load called twice, it runs after the room fades in. I have no idea why this is happening, but my first bet is always on user error.
Since it sounds like you haven't yet, please check the room's event section in the editor:

(http://i.imgur.com/QHWYj3h.png)

(Note that the name of the function does not matter at all; if you enter "room_Load" next to the "Repeatedly execute" event, the function room_Load() will get called 40 times per second, regardless of its name or content.)
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Wed 28/10/2015 01:12:03
No the Firstload works like a charm (and only at the first time (laugh)). I am using it to do a cutscene where an NPC is showing the room to the player. Isn't that, what this function is for? the help document says:
QuoteThis event occurs AFTER the screen has faded in, so it allows you to display a message describing the scene.
Maybe I should do that introduction in a one time if-prompt at AfterFadeIn instead?





Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Khris on Wed 28/10/2015 01:23:54
I have never used it but that's what the "First time enters room" event is for, yes. You can try and move the code to the "after fadein" event's function (and wrap it inside if (Game.DoOnceOnly("room x firstload")) { ... }).

Is this solved now? Or does it still fade twice? Are you using any Fade commands in your room script?
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Wed 28/10/2015 02:05:04
No. This didn't solve it. It does exactly the same, even after i deleted the firstload-function.

I am doing exactly the same (player walking to some waypoint, doing stuff until user gets control) in another room and don't have the problem there.

I think I have to analyze the code more intense to solve this. I will post my findings later.


Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Snarky on Wed 28/10/2015 06:57:45
Couple of things to check:

- Are you calling room_FirstLoad() from anywhere in the code?

- It doesn't seem to exactly match your description of what's happening, but is it possible that some code (maybe a region or room edge event) is sending the character out of the room even as it is loading?
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Kumpel on Wed 28/10/2015 17:58:00
Yes! I fixed it. There was a lazy character repositioning via player.ChangeRoom(Same Room, other coords) inside the Firstload function, which the engine recognized as "I have to do room_load after the firstload."

So it's as always what's in front of the monitor. (laugh)(roll)
Title: Re: Any way to prevent room load from getting called twice (b4/after r_firstload)?
Post by: Khris on Wed 28/10/2015 18:11:57
The engine recognized and processed it as regular command to change the room, which is what it did after FirstLoad() had finished. This new room change caused the second call to room_Load() and the fading (and a call to after-fadein, if present).
At that point the game stopped "misbehaving" because FirstLoad is only run once.

I did a test and added player.ChangeRoom(2) to room 2's after-fadein; that way the game gets stuck in an endless loop, fading out and in continuously.
I'm not sure this behavior is intentional; the fact that AGS does a regular room change even if new room == current room seems like a bug.

Anyway, glad this is solved.