playMaker

Author Topic: interrupting or exiting loops [SOLVED]  (Read 2535 times)

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
interrupting or exiting loops [SOLVED]
« on: July 21, 2018, 04:27:38 AM »
Hi all

I searched on google but couldn't find the answer.

I'm looping some states and that works fine - however I want to be able to always exit on a Key Up no matter what state the FSM is in - how can I do that? I somehow always get stuck on the Key Up or it's doing something else and not listening for the Key Up.

It's actually a general thing I've been struggling with with Playmaker - to have a FSM doing stuff but then always have a listener for a user input. On either a specific state or on the whole FSM.

Thank you!
« Last Edit: July 25, 2018, 05:02:44 AM by Caro »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: interrupting or exiting loops
« Reply #1 on: July 21, 2018, 06:19:11 AM »
Key up sucks, use get key and then test the bool.

You can either add listener in every state which is not a good solution, or a listener in separate FSM which will trigger a global transition in the first FSM that will break the loop.
Available for Playmaker work

Stuksgens

  • Playmaker Newbie
  • *
  • Posts: 9
Re: interrupting or exiting loops
« Reply #2 on: July 21, 2018, 06:56:11 PM »
Hello Cara

To exit a loop, you can;
1 - Placing an event in each state within the FSM is not very practical, but it works.
2 - You can create a separate FSM, where it sends a "send event" to the FSM that contains the loop, thus interrupting it.
3 - Or use the get key.

I hope you understood.  ;)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: interrupting or exiting loops
« Reply #3 on: July 22, 2018, 02:33:43 PM »
Hi.
Separate FSM with send events will work best in most cases.

Possible even multiple fsms for different keys, but that depends on your game.

For character movement i have (usually) minumum 3 fsms and goes up to more than 10 sometimes.

It is a good thing to split many parts into multiple fsms.

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
Re: interrupting or exiting loops
« Reply #4 on: July 23, 2018, 11:26:35 PM »
Thanks for your replies!

Okay so I clearly haven't understood this system correctly yet.

Key up sucks, use get key and then test the bool.

I tried this - i did "Get Key" Key: Space, Store Result: SpacePressed and then "Bool Test" that sends an event if true - but if I use that instead of "Key Up" it's just stuck on the first state (get time info)

1 - Placing an event in each state within the FSM is not very practical, but it works.

I can't see how that works - if it's stuck on another state, say Get Time Info for example - it will never get to the state where it's actually listening for the key?

Hi.
Separate FSM with send events will work best in most cases.

Okay I didn't know how this global event thing could be used, super cool - but I still don't understand the concept :p

So i've set a cube to change between red and blue every 1 second - and I then want to listen for an input to change to green. This could be done by a global event made in another FSM right? So I use no2 FSM to listen for the key but make the actual event in no1 FSM or? Just couldn't get this to work it didn't react on the key.

« Last Edit: July 23, 2018, 11:28:24 PM by Caro »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: interrupting or exiting loops
« Reply #5 on: July 24, 2018, 02:12:27 AM »
Here's an example

FSM 1 - Loops, or whatever it does



FSM 2 - Waits for key to be released, and sends an event to FSM 1




I used broadcast all, but generally, broadcast only to target receiver to avoid mess.

If you want to repeat, broadcast the global event to FSM 2 from FSM 1 to start "listening" when FSM 1 enter the looping states.
Available for Playmaker work

Caro

  • Playmaker Newbie
  • *
  • Posts: 22
Re: interrupting or exiting loops
« Reply #6 on: July 25, 2018, 05:02:34 AM »
Thank you so much for this clarification! I got it to work and I understand the basics now. <3 <3