playMaker

Author Topic: Struggling with greater than / else if in Playmaker  (Read 3314 times)

traitorjoe

  • Playmaker Newbie
  • *
  • Posts: 10
Struggling with greater than / else if in Playmaker
« on: June 28, 2014, 04:46:53 AM »
Hello!
I'm new to Playmaker but am fumbling my way through. However, I've spent hours trying to figure out the Playmaker approach to comparing variables in an "if / else if" sort of way, and I'm so stumped. I've found some juicy actions like Int Compare, but it still doesn't seem to be what I want.

How do you approach simple variable comparisons to say basically:
If var1 > 0, do a thing? The next part I'm stumped on is multiple variables like:
If var1 > 0 && var2 > 0 && var3 > 0 && var4 > 0, do a thing.
And lastly, is there a concept of "else" or "else if" when comparing variables?

Thanks in advance for any help you can offer!
« Last Edit: June 28, 2014, 04:51:22 AM by traitorjoe »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Struggling with greater than / else if in Playmaker
« Reply #1 on: June 28, 2014, 02:54:41 PM »
Branching is achieved with Events. You can use Logic Actions like Float Compare, Bool Test, or world tests like Game Object is Visible or Trigger Event to send events and branch your behaviour.

See attached image.

|    If var1 > 0, do a thing?

Use Float Compare to send an event and transition to the "do a thing" state.

|    is there a concept of "else" or "else if" when comparing variables?

Actions are executed in order, if an action doesn't trigger an event then the next action runs, which works like an "else."
Or you can use multiple states with TRUE/FALSE branching to express the algorithm like a flowchart. This is more work to setup, but is easier to follow and often exposes holes in your logic!

|    If var1 > 0 && var2 > 0 && var3 > 0 && var4 > 0, do a thing.

Either use multiple states as described above.
Or the new Conditional Expression Action (Beta):
http://hutonggames.com/playmakerforum/index.php?topic=7337.msg35523#msg35523

But I would encourage you to consider multiple states. It makes the algorithm clearer and helps you debug edge cases. You can also see the flow at runtime in the graph view and in the FSM Log. You can even pause the game and step back through all the state changes and examine variables etc.

It you want to collapse the states into their own graph you can use the Run FSM action: Make an FSM that does only the work you need and expose variables with the Inspector flag. Save this FSM as a template and you can run it at any time using Run FSM. Inspector variables will appear as parameters in the Run FSM action, so you can expose input parameters but keep the implementation details hidden inside the template. Essentially this lets you make your own actions inside Playmaker.
« Last Edit: June 28, 2014, 07:16:50 PM by Alex Chouls »

traitorjoe

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Struggling with greater than / else if in Playmaker
« Reply #2 on: June 28, 2014, 06:03:45 PM »
Thank you so much for the reply, Alex! That helps a lot!