playMaker

Author Topic: Bool Multi Test[SOLVED]  (Read 7668 times)

amaranth

  • Full Member
  • ***
  • Posts: 172
Bool Multi Test[SOLVED]
« on: October 05, 2012, 04:09:20 PM »
The following action can take several bools with different values and compare them all at once. It's the equivalent to this:

If (bool1 == true && bool2 == false && bool3 == false & bool4 == true)
{
   do this
}

To use it, do this:
(a) enter the number of bools to include in the statement in the Bool Variables field.
(b) enter the exact same number in the Bool States field.
(c) in Bool Variable (0) field, enter the variable with the bool.
(d) in Bool State (0) field, enter the state that the bool variable must be for this action to return True.
(e) repeat c & d for each additional variable that you add.

To get TRUE:
All bools variables must match the bool states that you selected.

To get FALSE:
If any bool variable does not match it's bool state.

The code:
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Tests if all the given Bool Variables are are equal to thier Bool States.")]
public class BoolTestMulti : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("This must be the same number used for Bool States.")]
public FsmBool[] boolVariables;

[RequiredField]
[Tooltip("This must be the same number used for Bool Variables.")]
public FsmBool[] boolStates;

public FsmEvent trueEvent;
public FsmEvent falseEvent;

[UIHint(UIHint.Variable)]
public FsmBool storeResult;

public bool everyFrame;

public override void Reset()
{
boolVariables = null;
boolStates = null;
trueEvent = null;
falseEvent = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoAllTrue();

if (!everyFrame)
Finish();
}

public override void OnUpdate()
{
DoAllTrue();
}

void DoAllTrue()
{
if (boolVariables.Length == 0 || boolStates.Length == 0) return;
if (boolVariables.Length != boolStates.Length) return;

bool allTrue = true;

for (int i = 0; i < boolVariables.Length; i++)
{
if (boolVariables[i].Value != boolStates[i].Value)
{
allTrue = false;
break;
}
}

storeResult.Value = allTrue;

if (allTrue)
Fsm.Event(trueEvent);
else
Fsm.Event (falseEvent);
}
}
}

In the image below, if B: Flag Right Wall is TRUE, and B: Flag Bottom Wall is FALSE, the stored result will be TRUE and the True Event is called.
« Last Edit: October 17, 2017, 02:33:45 AM by jeanfabre »

choi

  • Playmaker Newbie
  • *
  • Posts: 40
Re: Bool Multi Test
« Reply #1 on: October 05, 2012, 09:32:30 PM »
Quite useful in a multi-player game.
Thank you.

beowulfkaine

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Bool Multi Test
« Reply #2 on: April 27, 2017, 12:01:49 AM »
Thanks this really helped me

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Bool Multi Test
« Reply #3 on: April 27, 2017, 01:54:43 AM »
Hi,
There is a similar action on the ecosystem called : Bool Multi Condition

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • My Prototypes
Re: Bool Multi Test
« Reply #4 on: October 10, 2017, 01:02:19 PM »
Hello @djaydino,

This is probably the wrong place to post this but I did a quick search on Bool Multi test and it lead me to this post.
The Bool Multi Condition from the ecosystem works the same way as this script but the fail condition is not working along with the Everyframe function. It only check the condition once and then the action becomes disabled.

Tri Nguyen
Tri Nguyen
Game Designer at Nvizzio Creations

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Bool Multi Test
« Reply #5 on: October 12, 2017, 02:34:46 AM »
Hi,

 no this is a good place to ask.

 I fixed and updated that action, I also added a new result fsm variabl so that you can just store the results without the need for events.

 events will now be discrete as well meaning they are only sent when the condition has changed, instead of everyframe, which never make senses to call everyframe if the condition does not change. also it doesn't call finish when everyframe is selected.
 
I also added a better interface layout for book and conditions

 Let me know if that's ok ( redownload from the ecosystem)

 bye,

 Jean

omgitstri

  • Playmaker Newbie
  • *
  • Posts: 46
    • My Prototypes
Re: Bool Multi Test
« Reply #6 on: October 16, 2017, 12:03:23 PM »
Hello @jeanfabre

I tested the new version of BoolMultiCondition and it is working properly now. Thanks for the fix!

Tri Nguyen
Tri Nguyen
Game Designer at Nvizzio Creations