Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on September 16, 2012, 07:47:33 AM

Title: Multiple int compare
Post 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.

Code: [Select]
// (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
Title: Re: Multiple int compare
Post by: Graham on June 26, 2014, 11:52:11 AM
Huge thanks Jean, this action has just saved me a ton of time.
Title: Re: Multiple int compare
Post by: adentutton on March 21, 2015, 04:59:57 PM
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!
Title: Re: Multiple int compare
Post by: dudebxl on March 22, 2015, 05:04:44 PM
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.