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:
// (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.