playMaker

Author Topic: BoolAllTrueTest now also can send event if test fails  (Read 1269 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
BoolAllTrueTest now also can send event if test fails
« on: June 09, 2011, 02:46:37 AM »
Hi,

 A very simple addition to BoolAllTrue :https://hutonggames.fogbugz.com/default.asp?W469

 so that I can dispatch a event when the test fails, not just when the test passes. Avoids storing and checking, builds cleaner fsm. Also, I build a lot if states acting as "IF" statements with a "YES" and "NO" set of transitions ( or "TRUE" and "FALSE", whatever ). So this addition allows me to keep consistency in my fsms.

This can be easily applied to similar actions.

Here is the code ( also attached as a file as well for convenience).

Comments and feedback welcomed as always.

Bye,

 Jean

 
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 True. Ability to send event if test fails")]
public class BoolAllTrueTest : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmBool[] boolVariables;
public FsmEvent sendPassEvent;
public FsmEvent sendFailEvent;
[UIHint(UIHint.Variable)]
public FsmBool storeResult;
public bool everyFrame;

public override void Reset()
{
boolVariables = null;
sendPassEvent = null;
sendFailEvent = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoAllTrue();

if (!everyFrame)
Finish();
}

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

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

bool allTrue = true;

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

if (allTrue){
Fsm.Event(sendPassEvent);
}else{
Fsm.Event(sendFailEvent);
}

storeResult.Value = allTrue;
}
}
}

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • View Profile
    • FluidPlay Studios
Re: BoolAllTrueTest now also can send event if test fails
« Reply #1 on: June 11, 2011, 12:27:58 PM »
"If not all true" :) Cool, thanks for posting!
--
Breno "MaDDoX" Azevedo
@brenoazevedo