Author Topic: [SOLVED] how to detect room_leave from module?  (Read 239 times)  Share 

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
[SOLVED] how to detect room_leave from module?
« on: 08 Sep 2017, 17:50 »
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: Adventure Game Studio
  1. void room_Leave()
  2. {
  3.     Display("changed room");
  4. }
  5.  
  6. int player_prevRoom=-1; //cheap trick to detect room leave
  7. void DetectRoomLeave()
  8. {
  9.     if (player_prevRoom<0)
  10.         player_prevRoom = player.Room;
  11.     if (player_prevRoom!=player.Room)
  12.         room_Leave();
  13.     player_prevRoom=player.Room;    
  14. }
  15.  
  16.  
  17. void repeatedly_execute_always()
  18. {
  19.     DetectRoomLeave();
  20. }
  21.  

after posting this I'll be on my way investigating on_event and/or late_repeatedly_execute
« Last Edit: 15 Sep 2017, 14:59 by Monsieur OUXX »
 

Re: how to detect room_leave from module?
« Reply #1 on: 08 Sep 2017, 17:54 »
Leaving a room generates an eEvent for leaving the room

Code: Adventure Game Studio
  1. function on_event(EventType event, int data){
  2.     if(event == eEventLeaveRoom){
  3.       //do stuff
  4.     }
  5. }
  6.  
  7.  
« Last Edit: 08 Sep 2017, 17:58 by eri0o »

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: how to detect room_leave from module?
« Reply #2 on: 08 Sep 2017, 17:59 »
I've just tested on_event but it does it too early, BEFORE the fade out.
Now testing late_repeatedly_execute
 

Re: how to detect room_leave from module?
« Reply #3 on: 08 Sep 2017, 18:04 »
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

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: how to detect room_leave from module?
« Reply #4 on: 08 Sep 2017, 18:08 »
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

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Re: how to detect room_leave from module? [SOLVED]
« Reply #5 on: 08 Sep 2017, 18:37 »
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

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: how to detect room_leave from module? [SOLVED]
« Reply #6 on: 08 Sep 2017, 20:04 »
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

  • Global Moderator
  • Mittens Earl
  • Private Insultant
    • I can help with proof reading
    •  
    • I can help with translating
    •  
Re: how to detect room_leave from module? [SOLVED]
« Reply #7 on: 08 Sep 2017, 21:17 »
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

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: how to detect room_leave from module? [SOLVED]
« Reply #8 on: 10 Sep 2017, 16:34 »
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.