Global event for 'Player enters room after fadein' **SOLVED**

Started by Knox, Sat 18/12/2010 22:06:17

Previous topic - Next topic

Knox

Im aware of various work-arounds with variables and rep_exec, but if this can be avoided, that would be great.

I cant seem to find a global event for 'Player enters room after fadein'  (I just see eEventEnterRoomBeforeFadein)...does it exist in another form (or way to do it hidden in the manual somewhere?)

If this doesn't exist, how come? And...is there a way I can add "custom" global events? Id really like to avoid having to add the same lines into each room's AfterFadeIn.
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

You can somewhat simplify this by just creating a global function:

Code: ags
// GlobalScript.ash

import function enter_room_after_fadein();

// GlobalScript.asc

function enter_room_after_fadein()
{
  // do some generic stuff
  if (player.Room == X)
  {
    // do some room-specific stuff
  }
  // ...
}

// roomX.asc

function room_AfterFadein()
{
  enter_room_after_fadein(); // unfortunately this line still has to be duplicated..
  // but it's better than having to copy (and possibly update) multiple lines in every room
}


A global eEventEnterRoomAfterFadein has been requested..but..never really made the priority list. Presumably most people don't have a load of generic code to apply to every room once you can see what's going on.

Knox

Hey Monkey!

Ok, well that was one of the workarounds I tried, is there any way I can do it so I dont have to put code in each room script?

For example, this is what I did for a custom global script to be run in each room and I did it all from the global script...any way to get this to run with everything from the global script  (and not have to add anything in the room scripts)?

Code: ags

//on_event (EventType event, int data)
  if (event == eEventEnterRoomBeforeFadein)
  {    
       enterDir(player);
       if (bFollow == true) enterDir(cBuddy);
  }


The reason I would like a global eEventEnterRoomAfterFadein is because Ive written a script that detects which exit was used from a previous room (left, right, up or down), and upon entering "x" room, it checks the saved variable and runs the appropriate blocking animation of the player entering that room "x" to a specific spot...this saves me time.

Adding a new global event...is this something only CJ can do?
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Adding an event to on_event would require access to the engine source, which means that for now, yes only CJ could do that.

Well I just tested something pretty simple that might make this possible:

Code: ags
// GlobalScript.asc

bool afterFadein = false; // whether to fire the after fade-in event

function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein) afterFadein = true;
}

function repeatedly_execute()
{
  if ((afterFadein) && (!IsGamePaused()) && (IsInterfaceEnabled())) // the user interface is disabled until the room is faded in..
  {
    // do after fade-in stuff here
    afterFadein = false;
  }
}


Note that this will actually call the code in the global script after any room_AfterFadeIn event is called. However, that should give you a generic location to perform any tasks you need to after the room has faded in.

Calin Leafshade


Knox

Oh yea! Works great...I agree with Calin, quite clevah !

Thanks Monkey :)
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Just as a final test, I have found the precise order the functions are called:
1.  GlobalScript.asc, repeatedly_execute_always
2.  roomX.asc, repeatedly_execute_always
3.  roomX.asc, room_AfterFadeIn (or assigned "Enters room after fade-in" event handler)
4.  GlobalScript.asc, repeatedly_execute
5.  roomX.asc, room_RepExec (or assigned "Repeatedly execute" event handler)
Obviously you can't call any blocking functions in repeatedly_execute_always, but that is the first event that would be fired. So any non-blocking generic actions could go there.

Blocking generic interactions would have to go into the GlobalScript's repeatedly_execute, but just keep in mind as I said that it isn't fired until after the room's event handler. ;)

Edit: I didn't feel like posting again just to say this..so just FYI for anyone interested, I figured out the order of the function calls using AbortGame. I placed a call to AbortGame into each of the functions that I wanted to know the calling order of, and then commented out each one as they executed (testing the game 5 times in total). Could be a useful method if you need to figure out the calling order of other functions.

Knox

--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk