PlayMaker Updates & Downloads > Share New Actions

Int Compare And Flag

(1/2) > >>

MaDDoX:
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: ---// (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 "";
        }
    }
}
--- End code ---

tobbeo:
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:
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.

jeanfabre:
Can't find sarcasms neither. I guess it's just misunderstanding. Very useful action anyway :)

Bye,

 Jean

tobbeo:
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

Navigation

[0] Message Index

[#] Next page

Go to full version