playMaker

Author Topic: Event listening concern  (Read 2365 times)

cspeer504

  • Playmaker Newbie
  • *
  • Posts: 5
Event listening concern
« on: July 24, 2014, 11:16:38 AM »
Hello,

I don't yet own this product, but I've been watching tutorials to justify purchasing. So far, it looks like it would definitely save me time. However, I have a concern I'd like to have addressed before I commit to a purchase. I tried searching the forums but didn't find anything that helped:

In the tutorial videos there were a variety of FSMs created that would just listen for events and then process them when the event was eventually caught. The FSM processes the event by moving to another state to deal with event, and then back to the listening state to listen for the event again (i.e. Health Manager). If multiple events get thrown at this FSM (in the same or next frame), will this FSM set up have a chance at missing an event because it is in another state? If so, is there a way to prevent this using playmaker or would I have to write my own code? Any help is appreciated.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Event listening concern
« Reply #1 on: July 24, 2014, 11:48:45 AM »
This shouldn't be a problem. Each event is completely processed, including events it generates (e.g., by triggering a Send Event action), before processing the next event. E.g., returning to the listening state is normally part of that sequence. I say normally because you have to respect some rules:

Actions have 3 main phases: OnEnter, OnUpdate, OnExit.
If a state does all its work in OnEnter (usually when Every Frame is unchecked) then it can be part of a sequence all executed with one event. If it does work in OnUpdate then its work is spread out across updates.

Does that make sense? The main thing to remember is you can trigger a whole sequence of state changes with a single event in a single update.

cspeer504

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Event listening concern
« Reply #2 on: July 24, 2014, 12:52:09 PM »
Perfect! That's exactly the answer I was looking for. I'm a seasoned programmer and I've been looking for ways to save time on programming. Being a new father I don't have as much time as I used to have to spend on my projects. Playmaker is looking good so far!

If I may, I would like to piggy back on this thread to ask another question: I noticed some tutorials were setting up global variables with a reference to themselves (as shown here: http://youtu.be/7tT9LahdBW8?t=36m22s). Now this reference storage happens "immediately" if this is the first thing done on the FSM, but it appears another FSM could possibly beat the "manager" FSM and the global not yet contain the reference. Is there a way to ensure these managers set up first (without doing a generic delay for every FSM)?

600

  • Moderator
  • Hero Member
  • *****
  • Posts: 715
    • Flashing Lights
Re: Event listening concern
« Reply #3 on: July 25, 2014, 09:53:17 AM »
Hi,
yes you can.
For example I have in project:

1. A car (not global variables, but how to sequence fsms):
Fsm "Setup" gets wheels, material index for lights etc.
Then Streering or Movement and other FSM waits for State "DONE" on "Setup" fsm which is the last state. After that others load those variables.

2. Global var I have loads in Menu stage just before player loads a scene.

Could be other methods out there too :)

cspeer504

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Event listening concern
« Reply #4 on: July 25, 2014, 01:38:35 PM »
Thank you for the reply! This seems like a simple enough way of handling the problem. I was kind of hoping to find a solution that didn't require having all dependent FSMs to implement a wait action of any sorts.

One idea is to have an FSM loading priority queue with at least 2 levels: "Normal" and "High". All "High" priority FSMs would load before all "Normal" FSMs. So if you wanted certain FSMs to set up before others do, it would just require setting the priority to "High". The more levels, the more flexibility. I just purchased PlayMaker, so if I don't find a similar system (implemented or planned) I'll submit a feature request. Thanks again!  :D