playMaker

Author Topic: Single use FSM [SOLVED]  (Read 1384 times)

abend

  • Playmaker Newbie
  • *
  • Posts: 36
Single use FSM [SOLVED]
« on: September 21, 2019, 08:54:44 PM »
Hey Everybody!

I've got the handle of a regular self contained FSM. I have a few questions about using other FSMs, I can't seem to find anything that makes sense to me. Ok, First I have an object that has 2 FSMs on it - currently. One is the regular Loop, the other is like a cleaning up action. But it only does one thing, clean up. I want to call it from the first FSM, and maybe I have another object that after a specific action, I would call it then as well.

So If I have a loop of 4 events, and in the middle of the loop I call the sibling FSM - by send event? (I think Run FSM is just for templates, which I haven't looked into yet.) can I return to the loop where I left off?

Also I am a bit stuck with the one off FSM for cleanup. It never turns off.
Should all FSMs start with a listener of some kind instead of being forced to run by "calling" them in some way? I learned coding before I learned FSM, so calling and run a "function" when I want are the perspective I've come from. I understand it's different, I just can't get there yet.

Thanks!
« Last Edit: September 26, 2019, 03:57:09 AM by djaydino »

daniellogin

  • Full Member
  • ***
  • Posts: 215
Re: Single use FSM
« Reply #1 on: September 21, 2019, 11:11:35 PM »
/... I want to call it from the first FSM, and maybe I have another object that after a specific action, I would call it then as well.
Use Send Event. You need to create a Global Transition in your cleanup FSM. You create the event in the event tab, then tick the box next to the event to make it global. You then right click on the action and add a Global Transition. This will look a bit like how your FSM has a "START" above the first action, but now it will say the name of your new global transition above the action.

Now in your other FSM, you do Send Event, specify your cleanup FSM by first saying what GameObject it's attached to, then the actual name of the cleanup FSM, then enter the global transition you want to activate.

If this doesn't make sense, you should just check Youtube or Google for a tutorial with video/images. It's actually really simple but harder to explain with words alone.

Quote
So If I have a loop of 4 events, and in the middle of the loop I call the sibling FSM - by send event? ..../ can I return to the loop where I left off?
I don't get what you mean. Are you thinking by doing a Send Event that you are halting your FSM that did it? That's not the case. It will do that action and just keep flowing through your FSM. Now if you do want it to stop, flow it in to a dead end. Then put a global transition where you want it to continue again and use some other FSM to Send Event to that transition when you are ready.

Quote
FSM for cleanup. It never turns off.
Should all FSMs start with a listener of some kind instead of being forced to run by "calling" them in some way?

OK so it is common that you may need your FSM to wait until it's needed. Simply set your first state as blank. Just name it Idle or something, because it's not going anywhere.

Then you make a Global Transition on the state you want things to kick off in. Now another FSM can do a Send Event when the time is right to start it off. Now you can either have it loop from then on, OR, make yet another Global Transition that goes to your "Idle" state, so another FSM can also pause the flow again.

Again, I feel like it's hard to describe this with words. Read through this to get an idea of it, but use a video or tutorial with images to visualise it all. Don't worry, it's very simple and what you are describing is bread and butter for Play Maker, not unusual at all.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Single use FSM
« Reply #2 on: September 22, 2019, 05:04:45 AM »
Hi.

Here is a video about globals and locals :


abend

  • Playmaker Newbie
  • *
  • Posts: 36
Re: Single use FSM
« Reply #3 on: September 23, 2019, 05:04:22 PM »
Thanks guys! I feel like I made it to level 2!

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: Single use FSM
« Reply #4 on: September 25, 2019, 11:08:53 AM »
You can also check where the flow is in either FSM with Fsm State Switch and Fsm State Test.
They help you keep an eye on a FSM and if the observed state turns active, the action sends a positive.

With Get Fsm State, you obtain the name of the current state.

You can also find the data about who sent the event by collecting event info with Get event info... the action is named differently when you get the information, whereas when you set the information into an event you're going to pass to some other FSM or state inside the FSM, it's called Set event data.

With all this data, you can use both send event or go to state.

Go to previous state also works and this means you can hop back and forth between different states. For example, assuming you have simple group of operations that sit inside a single state, you can place it somewhere in your main FSM and virtually call it from different states with events or gotos and always return to the last state that called it.

abend

  • Playmaker Newbie
  • *
  • Posts: 36
Re: Single use FSM
« Reply #5 on: September 25, 2019, 04:37:28 PM »
I am starting to get the hang of this: