playMaker

Author Topic: Multiple int compare  (Read 6967 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Multiple int compare
« on: September 16, 2012, 07:47:33 AM »
Hi,

 following a request:
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

Graham

  • Sr. Member
  • ****
  • Posts: 340
  • I Love Playmaker!
    • Portfolio
Re: Multiple int compare
« Reply #1 on: June 26, 2014, 11:52:11 AM »
Huge thanks Jean, this action has just saved me a ton of time.
« Last Edit: June 26, 2014, 06:05:41 PM by Graham »
More templates on the Unity Asset Store!

Disclosure: We are using affiliate links to our assets; we may receive a commission for purchases made through them. This helps us to continue developing and maintaining great products!

adentutton

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Multiple int compare
« Reply #2 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!

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Multiple int compare
« Reply #3 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.