Playmaker Forum

Playmaker Updates & Downloads => Share New Actions => Topic started by: amaranth on October 05, 2012, 01:09:20 PM

Title: Bool Multi Test[SOLVED]
Post by: amaranth on October 05, 2012, 01: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.
Title: Re: Bool Multi Test
Post by: choi on October 05, 2012, 06:32:30 PM
Quite useful in a multi-player game.
Thank you.
Title: Re: Bool Multi Test
Post by: beowulfkaine on April 26, 2017, 09:01:49 PM
Thanks this really helped me
Title: Re: Bool Multi Test
Post by: djaydino on April 26, 2017, 10:54:43 PM
Hi,
There is a similar action on the ecosystem (https://hutonggames.fogbugz.com/default.asp?W1181) called : Bool Multi Condition
Title: Re: Bool Multi Test
Post by: omgitstri on October 10, 2017, 10:02:19 AM
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
Title: Re: Bool Multi Test
Post by: jeanfabre on October 11, 2017, 11:34:46 PM
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
Title: Re: Bool Multi Test
Post by: omgitstri on October 16, 2017, 09:03:23 AM
Hello @jeanfabre

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

Tri Nguyen