playMaker

Author Topic: In Between  (Read 4825 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
In Between
« on: March 19, 2012, 01:37:15 AM »
Hi,

 Following a request, please find IntBetween action that check that an int is between two values. There is an option to check for inclusive limits or not, it sends events, store the result in a boll and work everyframe if you want. So that should cover all situations.

[EDIT] modified to allow for reordering limits if min>max


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Logic)]
[Tooltip("Check if an int is between two values, ou can define limits as inclusive. Send Events and store results")]
public class IntBetween : FsmStateAction
{
[RequiredField]
public FsmInt integer;
[RequiredField]
public FsmInt integerMin;
[RequiredField]
public FsmInt integerMax;


[Tooltip("IF true, will pass test if integer is equal to the limits")]
public FsmBool inclusive;

[Tooltip("IF true, will reorder min and max ( if for example max is less then min, it will adjust). If False it will enforce the right limits declaration as per labels.")]
public FsmBool autoOrderLimits;

[Tooltip("Event sent if integer is between integerMin and integerMax")]
public FsmEvent isBetweenEvent;

[Tooltip("Event sent if Int 1 is less than Int 2")]
public FsmEvent isNotBetweenEvent;

[UIHint(UIHint.Variable)]
public FsmBool isInBetween;


public bool everyFrame;

public override void Reset()
{
integer = null;
integerMin = null;
integerMax = null;

inclusive = true;
autoOrderLimits = true;

isBetweenEvent = null;
isNotBetweenEvent = null;
isInBetween = null;

everyFrame = false;
}

public override void OnEnter()
{
DoIntBetween();

if (!everyFrame)
Finish();
}

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

void DoIntBetween()
{

int min = integerMin.Value;
int max = integerMax.Value;

if (autoOrderLimits.Value && min > max)
{
min = integerMax.Value;
max = integerMin.Value;
}

if (integer.Value < min || integer.Value > max)
{
Fsm.Event(isNotBetweenEvent);
isInBetween.Value = false;
return;
}

if (inclusive.Value)
{
if (integer.Value >= min && integer.Value <= max)
{
Fsm.Event(isBetweenEvent);
isInBetween.Value = true;
return;
}
}else
{
if (integer.Value > min && integer.Value < max)
{
Fsm.Event(isBetweenEvent);
isInBetween.Value = true;
return;
}
}

Fsm.Event(isNotBetweenEvent);
isInBetween.Value = false;

}

}
}


 Bye,

 Jean
« Last Edit: March 21, 2012, 03:50:17 AM by jeanfabre »

sefou

  • Playmaker Newbie
  • *
  • Posts: 11
Re: In Between
« Reply #1 on: March 19, 2012, 02:09:16 AM »
Thanks you.   :)

Dev_Sebas

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 398
    • Blog
Re: In Between
« Reply #2 on: March 19, 2012, 07:50:09 AM »
Thank you so muck Jean!! :) :D
Bye

CommanderPete

  • Playmaker Newbie
  • *
  • Posts: 17
Re: In Between
« Reply #3 on: March 20, 2012, 08:09:13 PM »
Hi Jean,
(implemented this into a function, but ran into trouble.
I have a row of states that check a global int variable for different ranges of int values (e.g. -100 to -250). If they are not in, they jump to the next state that checks ther next range. If they are in that range, they jump to a state that changes a bool variable. In my example I set the global to -120, but the In Between Event does not respond.)

... yeah well, if one puts -12000 into In Between Min and -25000 into In Between Max ... things might not work as expected ... should not work late in a smoking lounge of an airport  :P
Sorry having bothered the forum with that.

Cheers,
Lars
« Last Edit: March 20, 2012, 08:20:37 PM by CommanderPete »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: In Between
« Reply #4 on: March 21, 2012, 03:52:53 AM »
Hi Lars,

Actually, you have a good point, so you are not bothering at all :). I did thought about this when I created it and was too lazy to implement it to be honest... :)

 So I did it now ( edited the original post, so re download from there). don't hesitate to report if you find something else.

 Bye,

 Jean