playMaker

Author Topic: Global transitions and logic flow [Solved]  (Read 5779 times)

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Global transitions and logic flow [Solved]
« on: June 05, 2015, 07:35:50 AM »
I'm a bit confused about how an FSM handles global transitions and I'm hoping somebody can help me.

For example, I have an FSM that has a loop waiting for a touch event.  When it gets a touch, it starts a tween and then goes back into the loop.  Easy enough.

However, the tween has a finish event that calls a global transition in the same FSM.  When it finishes, it does some cleanup work and then goes back into the waiting-for-touch loop.

My question is how do these two separate portions of the FSM work in tandem?  Is the touch input loop still running when the tween finish is running?  Do I need to keep separate variables for each section so they don't collide?  For example, I have a Touched Object variable.  But it seems like it could be different for each section if there's a new touch being processed at the same time as a tween is finishing.

Attached is a simplified version of the scenario.

Any clarification would be much appreciated.  Thanks!
« Last Edit: June 10, 2015, 04:25:30 PM by Tricky_Widget »

thatnzguy

  • Playmaker Newbie
  • *
  • Posts: 43
Re: Global transitions and logic flow
« Reply #1 on: June 07, 2015, 05:06:29 PM »
If you could post a screenshot that would help clarify some things.

But it sounds like you're trying to run two separate FSMs in the same FSM?
If that is the case, consider that any FSM can only run one state at a time, if you want parallel states you will have to create multiple FSMs.

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Re: Global transitions and logic flow
« Reply #2 on: June 09, 2015, 08:43:34 AM »
Added a diagram to the original post.  Thanks!

thatnzguy

  • Playmaker Newbie
  • *
  • Posts: 43
Re: Global transitions and logic flow
« Reply #3 on: June 09, 2015, 04:30:43 PM »
Instead of looping the state, do the actions have a check box 'every frame'? This will run the action in the state every frame until the event is fired.

I assume in Tween Start you're using an iTween? Why not go from Tween Start to Tween Finish ?

If it's rather complicated, you could post screenshots of the actions in each state, or post a package and I'll check it out.

It's a little hard to guess what's going on inside each state

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Re: Global transitions and logic flow
« Reply #4 on: June 09, 2015, 04:32:51 PM »
Why not go from Tween Start to Tween Finish ?
...
It's a little hard to guess what's going on inside each state

Tweens take some amount of time to complete, so there can't be a direct link between one state and the next.  And the question isn't about the particulars of what's going on inside the states, but rather how PM handles the logic flow in this situation.

thatnzguy

  • Playmaker Newbie
  • *
  • Posts: 43
Re: Global transitions and logic flow
« Reply #5 on: June 09, 2015, 07:02:33 PM »
I can't figure out what is calling Tween Finish, I understand the basic Check Input loop > Tween Start > back to Check Input. But there must be a parallel fsm running somewhere that returns Tween Finish later.

Returning to your questions in the OP:

Quote
My question is how do these two separate portions of the FSM work in tandem? Is the touch input loop still running when the tween finish is running?  Do I need to keep separate variables for each section so they don't collide?

Only one state will run at a time.

One thing that can be confusing is that the iTween actions provide an event field for Start and Finish. If you use Start it will immediately fire and Finish will never fire.

Use the PlayMaker > Editor Windows > Log Window to see how the states have run. I often pause the game and step through frame by frame to follow it.

You can also jump in the chat for quicker responses.

https://jabbr.net/#/rooms/PlayMakerDev

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Re: Global transitions and logic flow
« Reply #6 on: June 10, 2015, 07:28:10 AM »
I can't figure out what is calling Tween Finish

I appreciate your attempts to help, but I'm afraid you don't understand the question.  :)

I'm well versed in the basics of PM.  This is about how global transitions are handled relative to the "start" transition.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Global transitions and logic flow
« Reply #7 on: June 10, 2015, 07:45:05 AM »
There is only ever one active state at any given time. In your case (and all cases) the two states are unrelated entirely. There isn't any tandem or parallel work ever taking place because you must be in either one state or the other at any given time. The only form of connection they share is the use of variables inside the FSM which they both may be changing individually and that is really the extent of their relationship and entirely in your control.

When you fire an event through a transition it simply knows where to go from the current state because you have connected it explicitly. It's similar with global transitions, its still a fundamentally basic 'transition' except that it is not explicitly connected, but rather is found via name of that global event and does not require a transition line to connect it.

Also, in the case of tweens, code runs outside of Playmaker as a separate script, I think there is a toggle something like "stop on exit" which will stop the outside script when the state exits. If you don't make use of that toggle then the code is out of scope in respect to the FSM. Although, I'm not super clear on the extent of how tweens work in regards to that because I didn't make the actions and haven't had much need to look into it.. (eg, if the Tween has a unique key to associate it to the state to avoid duplication, etc..)
« Last Edit: June 10, 2015, 07:50:30 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Re: Global transitions and logic flow
« Reply #8 on: June 10, 2015, 03:56:39 PM »
There is only ever one active state at any given time.
I thought as much, but I'm confused about the input loop vs the global transition.  The input loop is firing every frame.  And then at some arbitrary time, the global transition fires.  Then what happens to the input loop?  Does it simply abort the loop and direct the FSM into the global transition state?  (This is what it seems to do from my experimenting.)

Also, in the case of tweens, code runs outside of Playmaker as a separate script...
I'm actually using LeanTween with custom actions (I just said iTween because it's more familiar and they seem to work in the same manner).  I simply set the tween complete callback to a function inside tween start action.  And then in that function I do a basic Fsm.Event(FsmEvent).  After I start the tween, it continues to run on its own when the calling state exits.  So the finish event (and it's global transition) fires arbitrarily somewhere in the middle of the input loop.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Global transitions and logic flow
« Reply #9 on: June 10, 2015, 04:21:10 PM »
There is only ever one active state at any given time.
I thought as much, but I'm confused about the input loop vs the global transition.  The input loop is firing every frame.  And then at some arbitrary time, the global transition fires.  Then what happens to the input loop?  Does it simply abort the loop and direct the FSM into the global transition state?  (This is what it seems to do from my experimenting.)

Yes, you told it to do something else so it does it.

Quote
Also, in the case of tweens, code runs outside of Playmaker as a separate script...
I'm actually using LeanTween with custom actions (I just said iTween because it's more familiar and they seem to work in the same manner).  I simply set the tween complete callback to a function inside tween start action.  And then in that function I do a basic Fsm.Event(FsmEvent).  After I start the tween, it continues to run on its own when the calling state exits.  So the finish event (and it's global transition) fires arbitrarily somewhere in the middle of the input loop.

I haven't used LeanTween, not sure how it handles things. Global transitions being fired in the state will always override whatever else is happening in the FSM in order to get to the target transition state. That is part of their purpose.

If you want parallel logic, just make more FSMs.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Tricky_Widget

  • Junior Playmaker
  • **
  • Posts: 62
Re: Global transitions and logic flow
« Reply #10 on: June 10, 2015, 04:25:17 PM »
If you want parallel logic, just make more FSMs.
I don't want it.  :)  I asked because I was afraid I might get it, which would mangle my variables.

Global transitions being fired in the state will always override whatever else is happening in the FSM in order to get to the target transition state.
Ah, that's the crux.  Just what I needed to know.  Thank you very much!