playMaker

Author Topic: Interrupting/pausing a sent event?  (Read 2658 times)

playmakerNewb

  • Playmaker Newbie
  • *
  • Posts: 15
Interrupting/pausing a sent event?
« on: June 25, 2012, 11:10:51 AM »
I've got several FSM's in my scene that all listen out for various events over time.  That being said, I'm looking for a way to hook in to the current event system to address three issues.

1.  If my game is paused, don't send a delayed event.  I have a partial solution of this. (Simply don't fire the event IF paused)

2.  If my game is in a certain state (say a full screen GUI is displayed and the game is in a gui state), ignore and hold any background events from occuring.

3.  Listen for incoming events and handle appropriately if paused.  Capture the event and delay until the game is un-paused (or until a state changes).

The problem I'm having is the following.

A delayed event is spawned from some gameobject fsm with a timer of N seconds.  The user pauses the game, or the game changes internal state.  Since time is still happening in the background, the event fires and all FSM's react appropriately.  I need a way to either block, stop, pause, or listen out for these background events...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Interrupting/pausing a sent event?
« Reply #1 on: June 25, 2012, 03:12:43 PM »
Hi,

 I faced this issue, but for something else than pausing, but the solutions are very similar.

basically a delayed event will fire even if you leave the state you fired it from, which can be seen as a bug, but it's actually by design.

 the way to go about it is to not used the built in delay but rather implement your own timer solution, using a float and the current time, etc etc it's involving but it works. so when pausing, you kill the process and only retain the current elapsed time, when unpausing, you resume the timer and start counting from that elapsed time.

So,

1: Interested to know what you came up with

2: I don't think you can "hold" events, you will need to explicitly design your fsm to accomodate this. I do that on many occasion, it simply means maintaining a game "context" that when the fsm must comply too at key states, so for example pausing would mean calling a specific state and record here the current status of this fsm, maybe a variable or the last active state, and when unpausing, again a specific state that will resume this fsm.

This is tedious. I also implement another method which requires a fsm to ONLY have one starting point, and goes through all the required statements and checks to know where it should carry on what it was doing. This is difficult to put in place but extremely rewarding in terms of flexibility.

3: Yes, you could have a global var called "paused" and on key states first check if the game is paused or not, but that is going to bloat your fsm with a lot of redundant states and checks, which will in the long run make it difficult to edit, change the behavior globally etc etc,

Bye,

 Jean

playmakerNewb

  • Playmaker Newbie
  • *
  • Posts: 15
Re: Interrupting/pausing a sent event?
« Reply #2 on: June 26, 2012, 09:40:45 AM »
I've found a temporary solution for now.  Basically, any time I either need to pause, or I need to stop background events from happening, I either stop or slow down the time scale using Time.timeScale.  This is working for me right now in 99.9% of my instances (such as when the game is paused).  I simply set the time scale to 0 then, and back to 1 on restart.  No issues so far...