playMaker

Author Topic: Check if a number is between two(INT and FLOAT)  (Read 6958 times)

KirbyRawr

  • Playmaker Newbie
  • *
  • Posts: 16
    • Overflowing Team
Check if a number is between two(INT and FLOAT)
« on: November 08, 2013, 08:32:20 PM »
Hi, today i wanted to share my new custom action i needed to do.
It gives you the possibility to check if a number is between two ^^



FLOAT ACTION
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
//Made by KirbyRawr from www.overflowingstudios.com, enjoy it :P
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("This custom action check if a number is between two")]
public class CheckNumberBetweenTwoFloat : FsmStateAction
{
[RequiredField]
public FsmFloat number0;

public FsmFloat numberBetween;

public FsmFloat number1;

public FsmEvent yes;

public FsmEvent no;

public bool everyFrame;

public override void Reset()
{
number0 = 0;
numberBetween = 0;
number1 = 0;
everyFrame = false;
yes = null;
}

public override void OnEnter()
{
DoCompare();

if (!everyFrame)
{
    Finish();
}
}

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

void DoCompare()
{

if(number0.Value < numberBetween.Value && numberBetween.Value < number1.Value){
Fsm.Event(yes);
}

else{
Fsm.Event(no);
}

}
}
}

Now with Int action!

INT ACTION
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
//Made by KirbyRawr from www.overflowingstudios.com, enjoy it :P
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("This custom action check if a number is between two")]
public class CheckNumberBetweenTwoInt : FsmStateAction
{
[RequiredField]
public FsmInt number0;

public FsmInt numberBetween;

public FsmInt number1;

public FsmEvent yes;

public FsmEvent no;

public bool everyFrame;

public override void Reset()
{
number0 = 0;
numberBetween = 0;
number1 = 0;
everyFrame = false;
yes = null;
}

public override void OnEnter()
{
DoCompare();

if (!everyFrame)
{
    Finish();
}
}

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

void DoCompare()
{

if(number0.Value < numberBetween.Value && numberBetween.Value < number1.Value){
Fsm.Event(yes);
}

else{
Fsm.Event(no);
}

}
}
}
« Last Edit: November 12, 2013, 04:21:28 PM by KirbyRawr »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Check if a number is between two
« Reply #1 on: November 11, 2013, 01:34:29 AM »
Hi,

 Good, but you forgot to implement the Update function to account for when "everyFRame" is set to true.

Also, you are aware that you can do that with two "Float compare" or "Int Compare" actions right?

bye,

 Jean

KirbyRawr

  • Playmaker Newbie
  • *
  • Posts: 16
    • Overflowing Team
Re: Check if a number is between two
« Reply #2 on: November 11, 2013, 09:37:51 AM »
Hi,

 Good, but you forgot to implement the Update function to account for when "everyFRame" is set to true.

Also, you are aware that you can do that with two "Float compare" or "Int Compare" actions right?

bye,

 Jean

Thanks Jean, i will try to fix it asap, and yeah i tried with "compare" but i like to have it on one script, more flexible :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Check if a number is between two
« Reply #3 on: November 12, 2013, 12:03:30 AM »
Hi

 Yes, I just wanted to make sure, I also like this custom action very much indeed. You should do one for ints as well.

Bye,

Jean

KirbyRawr

  • Playmaker Newbie
  • *
  • Posts: 16
    • Overflowing Team
Re: Check if a number is between two(INT and FLOAT)
« Reply #4 on: November 12, 2013, 02:46:30 PM »
Added Int support, i need to fix the every time thing i will do it tomorrow so don't worry :)

EDIT: OKEY fixed i think :)
« Last Edit: November 12, 2013, 04:21:45 PM by KirbyRawr »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Check if a number is between two(INT and FLOAT)
« Reply #5 on: November 14, 2013, 12:16:22 AM »
Hi,

 Nice, thanks!

bye,

 Jean

bkups2003

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Check if a number is between two(INT and FLOAT)
« Reply #6 on: November 17, 2013, 10:07:54 PM »
Just yesterday i needed to have a check if an int was between 2 values. Did it with compares and bools. A little too early for this action. Thanks again. This is very useful.