[SOLVED] how to detect room_leave from module?

Started by Monsieur OUXX, Fri 08/09/2017 17:50:57

Previous topic - Next topic

Monsieur OUXX

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

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
 

eri0o

#1
Leaving a room generates an eEvent for leaving the room

Code: ags

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


Monsieur OUXX

#2
I've just tested on_event but it does it too early, BEFORE the fade out.
Now testing late_repeatedly_execute_always
 

eri0o

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.

Monsieur OUXX

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.
 

Crimson Wizard

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.

Monsieur OUXX

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.
 

Snarky

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.

Monsieur OUXX

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.
 

SMF spam blocked by CleanTalk