playMaker

Author Topic: Float Compare Set Value  (Read 6751 times)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Float Compare Set Value
« on: August 02, 2011, 10:36:16 PM »
If anyone wants it i just made a Float Compare Set Value Action by modifying the Float Compare Action... It just compares two floats and then lets you supply a float and then will set the value of that float to a float set in any of the 3 outcomes.. equal etc..

It totally simplified my FSM in a huge way..

Q

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15398
  • Official Playmaker Support
    • View Profile
Re: Float Compare Set Value
« Reply #1 on: August 03, 2011, 03:16:53 AM »
Hi,

 Simply attach the script or paste the code in the thread. then if it comes handy, it's there already.

 Bye,

 Jean

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Compare Set Value
« Reply #2 on: August 03, 2011, 08:11:16 AM »
Hehh yes i will.. i am just not on my dev machine so it was just a quick note from late last night.. will do it later today.

Q

joeyjr

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Float Compare Set Value
« Reply #3 on: August 09, 2011, 07:53:30 AM »
Where is this script? How do I access it?

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Compare Set Value
« Reply #4 on: August 09, 2011, 08:14:21 AM »
Right.. i forgot.

So this Action will compare two float values and then will set a 3rd provided float to 1 of 3 different provided values.. So if it compares the 2 values and they are equal then it will set the provided variable to what you have in the Equal location and so on...

I cant remember why i needed this but it was a real time saver for some logic i was doing.

Hope it helps someone.

Q

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Sets Provided Float Variable to a Provided Value based on the comparison of 2 Floats.")]
public class FloatCompareSetValue : FsmStateAction
{
[RequiredField]
public FsmFloat float1;
[RequiredField]
public FsmFloat float2;
[RequiredField]
public FsmFloat tolerance;
[RequiredField]
[Tooltip("Float Variable to Set to different outcome values")]
public FsmFloat floatToChange;
[Tooltip("Value to Set if Float 1 equals Float 2 (within Tolerance)")]
public FsmFloat equal;
[Tooltip("Value to Set if Float 1 is less than Float 2")]
public FsmFloat lessThan;
[Tooltip("Value to Set if Float 1 is greater than Float 2")]
public FsmFloat greaterThan;
public bool everyFrame;

public override void Reset()
{
float1 = 0f;
float2 = 0f;
tolerance = 0f;
floatToChange = 0f;
equal = 0f;
lessThan = 0f;
greaterThan = 0f;
everyFrame = false;
}

public override void OnEnter()
{
DoCompare();

if (!everyFrame)
Finish();
}

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

void DoCompare()
{

if (Mathf.Abs(float1.Value - float2.Value) <= tolerance.Value)
{
floatToChange.Value = equal.Value;
return;
}

if (float1.Value < float2.Value)
{
floatToChange.Value = lessThan.Value;
return;
}

if (float1.Value > float2.Value)
{
floatToChange.Value = greaterThan.Value;
return;
}

}

public override string ErrorCheck()
{

return "";
}
}
}

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: Float Compare Set Value
« Reply #5 on: August 09, 2011, 02:10:17 PM »
Well I did look for this, but did not find the action so I just made some normal code for it..lol

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Compare Set Value
« Reply #6 on: August 09, 2011, 02:17:18 PM »
Yes i have been doing that a lot so i have been making lots of Actions.. I hope they prove useful in the future.

Now you have a choice!

Q

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • View Profile
    • Permaximum Betty
Re: Float Compare Set Value
« Reply #7 on: August 09, 2011, 02:32:24 PM »
Well i have no clue right now what it was. lol
But I guess it will be useful when I start doing some more games or improve the latest game.. :-P


qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Float Compare Set Value
« Reply #8 on: August 09, 2011, 02:40:00 PM »
funny i would have to go looking for it in my project.. i have no idea where it is. Or why i needed it. Oh well i am sure i was happy at the time.

Q