Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on September 16, 2012, 07:47:33 AM
-
Hi,
following a request:
http://hutonggames.com/playmakerforum/index.php?topic=2284.0 (http://hutonggames.com/playmakerforum/index.php?topic=2284.0)
Please find an action that check if any number of ints are equals or not.
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Sends Events based on the comparison of multiple Integers.")]
public class IntEquals : FsmStateAction
{
[RequiredField]
public FsmInt[] integers;
[Tooltip("Event sent if all ints equal")]
public FsmEvent equal;
[Tooltip("Event sent if ints not equal")]
public FsmEvent notEqual;
public bool everyFrame;
public override void Reset()
{
integers = new FsmInt[2];
equal = null;
notEqual = null;
everyFrame = false;
}
public override void OnEnter()
{
DoIntCompare();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoIntCompare();
}
void DoIntCompare()
{
if (integers.Length>1)
{
int _base = integers[0].Value;
foreach(FsmInt _int in integers)
{
if (_base!= _int.Value)
{
Fsm.Event(notEqual);
return;
}
}
}
Fsm.Event(equal);
}
public override string ErrorCheck()
{
if (FsmEvent.IsNullOrEmpty(equal) &&
FsmEvent.IsNullOrEmpty(notEqual))
return "Action sends no events!";
if (integers.Length <2)
{
return "Action needs more than 1 int to compare";
}
return "";
}
}
}
bye,
Jean
-
Huge thanks Jean, this action has just saved me a ton of time.
-
Hi!
I've just found this add-on which would help me but I need to use the same comparison for Floats, would this script be easy to edit?
Hope someone can help!
Thanks!
-
Hi,
I saw your post and I also needed something to compare floats so here you go:
http://hutonggames.com/playmakerforum/index.php?topic=9910.0
It has the same principles as the 'int equals' action but for floats with float tolerances (+bool & +event).
In a new post to allow clean search.
Hope it helps you.