playMaker

Author Topic: Int Compare And Flag  (Read 7746 times)

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Int Compare And Flag
« on: April 12, 2011, 07:53:26 PM »
Another action following my approach of integrating some logic statements into actions that don't leave the state. This is action is similar to the standard Int Compare (with equal, greater than and lesser than possible outcomes) but instead of switching to a new state it simply assigns a chosen value to a boolean variable (called "flag"). Another remarkable difference from the original Int Compare is that it actually executes the outcomes of greater than or equal (>=) and lesser than or equal (<=) without a problem. Fields should be self explanatory, I find it especially handy for "AND" conditions. Here's a practical use case:

Enjoy!

PS.: I could've tested this one a bit more btw, so if you find any issues just report back and I'll fix it.

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

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Logic)]
    [Tooltip("Assigns values to boolean variables based on the comparison of 2 Integers.")]
    public class IntCompareAndFlag : FsmStateAction
    {
        [RequiredField]
        public FsmInt integer1;
        [RequiredField]
        public FsmInt integer2;
        [Tooltip("Variable to flag if Int 1 equals Int 2")]
        [UIHint(UIHint.Variable)]
        public FsmBool boolEqualVariable;
        public FsmBool boolEqualValue;
        [Tooltip("Variable to flag if Int 1 is less than Int 2")]
        [UIHint(UIHint.Variable)]
        public FsmBool boolLesserThanVariable;
        public FsmBool boolLesserThanValue;
        [Tooltip("Variable to flag if Int 1 is greater than Int 2")]
        [UIHint(UIHint.Variable)]
        public FsmBool boolGreaterThanVariable;
        public FsmBool boolGreaterThanValue;

        public bool everyFrame;

        public override void Reset()
        {
            integer1 = 0;
            integer2 = 0;
            boolEqualVariable = null;
            boolEqualValue = true;
            boolLesserThanVariable = null;
            boolLesserThanValue = true;
            boolGreaterThanVariable = null;
            boolGreaterThanValue = true;
            everyFrame = false;
        }

        public override void OnEnter()
        {
            DoIntCompare();

            if (!everyFrame)
                Finish();
        }

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

        void DoIntCompare()
        {
            if (integer1.Value == integer2.Value)
            {
                boolEqualVariable.Value = boolEqualValue.Value;
            }

            if (integer1.Value < integer2.Value)
            {
                boolLesserThanVariable.Value = boolLesserThanValue.Value;
                return;
            }

            if (integer1.Value > integer2.Value)
            {
                boolGreaterThanVariable.Value = boolGreaterThanValue.Value;
                return;
            }

        }

        public override string ErrorCheck()
        {
            if (boolEqualVariable == null &&
                boolLesserThanVariable == null &&
                boolGreaterThanVariable == null)
                return "Action has no boolean flags selected!";
            return "";
        }
    }
}
« Last Edit: April 12, 2011, 07:55:35 PM by MaDDoX »
--
Breno "MaDDoX" Azevedo
@brenoazevedo

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Int Compare And Flag
« Reply #1 on: April 12, 2011, 09:18:05 PM »
Thanks! Useful if you want to test value and stay in state. Sarcasm against Playmaker dev was a bit unnecessary though... He fixed it and posted it didn't he?

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Int Compare And Flag
« Reply #2 on: April 13, 2011, 08:20:03 AM »
Hmm? Where did you find me sarcastic? ??? I tend to be very good at that but I really didn't intend any.. I simply haven't tested this action as thoroughly as I generally do, I was just saying that if something doesn't work properly with it just tell me and I'll fix it. If you thought I was offering to fix default actions.. well, you got me completely wrong.

Peace.
--
Breno "MaDDoX" Azevedo
@brenoazevedo

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Int Compare And Flag
« Reply #3 on: April 13, 2011, 10:30:14 AM »
Can't find sarcasms neither. I guess it's just misunderstanding. Very useful action anyway :)

Bye,

 Jean

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Int Compare And Flag
« Reply #4 on: April 13, 2011, 11:13:17 AM »
Sorry if I misunderstood, it was this that I thought you were taking a jab:

"Another remarkable difference from the original Int Compare is that it actually executes the outcomes of greater than or equal (>=) and lesser than or equal (<=) without a problem."

Since that was a bug in the Int Compare that wasn't working right. Sorry if I misunderstood! :)

Tobbe

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Int Compare And Flag
« Reply #5 on: April 13, 2011, 05:29:38 PM »
Since that was a bug in the Int Compare that wasn't working right. Sorry if I misunderstood! :)

Owww, gotcha, but that's not even a bug! ;D How could both the equal and greater/lesser outcomes be executed at once, if as soon as the equal outcome is executed the execution flow is drawn to another state? Since I'm just assigning values, I can do it twice in the same action without a problem.

To explain it even better, if in the regular Int Compare you assign, say, the 'greater than' and the 'equal' results to the same state, it'll work as a greater than or equal anyways 'coz at least one condition was achieved, and the result will be the same. What I was originally referring to is that with Int Compare and Flag you can have two different outcomes, one for the "greater" (say, making 'gtvar = false') and one for the "equal" (say, making 'eqvar = true').

Hope that clears everything up :)
--
Breno "MaDDoX" Azevedo
@brenoazevedo

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Int Compare And Flag
« Reply #6 on: April 13, 2011, 08:00:11 PM »
Aaah now I understand, sorry! :)