Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Monsieur OUXX on Fri 08/09/2017 17:50:57

Title: [SOLVED] how to detect room_leave from module?
Post by: Monsieur OUXX on Fri 08/09/2017 17:50:57
Hello,

I want to automatically run some script during the black screen inbetween fade out/fade in.
This script is long and complex and might freeze the screen half a sceond. That's why I want to do it at the exact moment when the player does expect the game to be unresponsive.
I want this script to run at EVERY room change, no matter what. So it should happen automatically.

therefore the question is : how do I automatically pick that up?

I've tried this but it seems to be triggered only after the end of the fade in (I suppose AGS doesn't happen player.Room until then?)

Code (ags) Select

void room_Leave()
{
    Display("changed room");
}

int player_prevRoom=-1; //cheap trick to detect room leave
void DetectRoomLeave()
{
    if (player_prevRoom<0)
        player_prevRoom = player.Room;
    if (player_prevRoom!=player.Room)
        room_Leave();
    player_prevRoom=player.Room;   
}


void repeatedly_execute_always()
{
    DetectRoomLeave();
}


after posting this I'll be on my way investigating on_event and/or late_repeatedly_execute_always
Title: Re: how to detect room_leave from module?
Post by: eri0o on Fri 08/09/2017 17:54:48
Leaving a room generates an eEvent for leaving the room

Code (ags) Select

function on_event(EventType event, int data){
    if(event == eEventLeaveRoom){
      //do stuff
    }
}

Title: Re: how to detect room_leave from module?
Post by: Monsieur OUXX on Fri 08/09/2017 17:59:22
I've just tested on_event but it does it too early, BEFORE the fade out.
Now testing late_repeatedly_execute_always
Title: Re: how to detect room_leave from module?
Post by: eri0o on Fri 08/09/2017 18:04:50
If that doesn't work, the workaround I would sugest would be using a GUI thats fully black screensized and tweening it's transparency, and using the instant screen  transition. Then you could create your own screen transition module.
Title: Re: how to detect room_leave from module?
Post by: Monsieur OUXX on Fri 08/09/2017 18:08:20
Yes I've considered that but I didn't want it to conflict with the built-in transitions system.

However, the solution was actually extremely simple: instead of using on_event for eEventLeaveRoom, all I had to do was ot use for eEventEnterRoomBeforeFadein. My script is executed during pitch black. SOLVED.
Title: Re: how to detect room_leave from module? [SOLVED]
Post by: Crimson Wizard on Fri 08/09/2017 18:37:42
Quote from: Monsieur OUXX on Fri 08/09/2017 18:08:20
Yes I've considered that but I didn't want it to conflict with the built-in transitions system.

Surely, you could always just turn it off by setting "instant" built-in transition and script custom transitions for your game. This will give even more control for the case like this.
Title: Re: how to detect room_leave from module? [SOLVED]
Post by: Monsieur OUXX on Fri 08/09/2017 20:04:23
Quote from: Crimson Wizard on Fri 08/09/2017 18:37:42
Surely, you could always just turn it off and script custom transitions for your game.

True. But really, all my scripts put together add up to such a monster that anything blocking the standard behaviours is a threat to my sanity (in 6 months I might be trying to understand why the selected room transiton doesn't work, only to find out in some obscure part of my code that I've rewritten it).

eEventEnterRoomBeforeFadein definitely works like a charm.
Title: Re: how to detect room_leave from module? [SOLVED]
Post by: Snarky on Fri 08/09/2017 21:17:01
Personally I think the built-in fade-in/fade-out functions should not be used anyway (in any fairly ambitious game), because the way they freeze background animations is so ugly.
Title: Re: how to detect room_leave from module? [SOLVED]
Post by: Monsieur OUXX on Sun 10/09/2017 16:34:20
Quote from: Snarky on Fri 08/09/2017 21:17:01
Personally I think the built-in fade-in/fade-out functions should not be used anyway (in any fairly ambitious game), because the way they freeze background animations is so ugly.
I had the same opinion until I realized that, in the end, it's failry unnoticeable -- once you get yourself to be used to "old-school" again. From experience it takes only around 10 minutes of playing Fate of Atlantis until all the ugliness starts fading out and you start finding the art and stuff like that pretty again.