playMaker

Author Topic: Float/Int Subtract  (Read 10037 times)

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Float/Int Subtract
« on: January 14, 2015, 08:04:55 PM »
I said this when I first got playmaker and I'll keep saying it:  If there is a 'float add' then there should be a 'float subtract'.  If there is a 'int add' there should be a 'int subtract'.  I know you put in '-1' to subtract BUT, for beginners this is very difficult to figure out.  Also, in the browser, you see a list of actions.  If you see a 'add' you think something is being added which may not be the case.  For Lane or Jeanfabre this would take less than 1 minute to add.  Not a big deal and makes playmaker friendlier.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: Float/Int Subtract
« Reply #1 on: January 15, 2015, 02:19:26 AM »
Hi,

 You have a float operator action that let's you do substraction, so it's covered.

But I agree, it may be difficult for beginners to find it. Keep bumping please :) I'll do that eventually.

also, for all the members willing to get into scripting and custom action development, this is a very easy action to do, so I would encourage you to give it a go, post here and I'll review them.

 
 Bye,

 Jean

600

  • Moderator
  • Hero Member
  • *****
  • Posts: 719
    • 600
Re: Float/Int Subtract
« Reply #2 on: January 15, 2015, 06:27:23 AM »
Hello,

I found Float Subtract in default Playmaker actions folder.
And made some changes to IntAdd to work as Subtract, please check the attachment for both actions.

wheretheidivides

  • Sr. Member
  • ****
  • Posts: 496
Re: Float/Int Subtract
« Reply #3 on: January 15, 2015, 10:15:53 PM »
How easy was that?  I personally don't need the subtract cause I know to do '-1', however there are a lot of people that are just starting out that will be looking for it.  These should go in the official playmaker set of actions.  Good job.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: Float/Int Subtract
« Reply #4 on: January 16, 2015, 03:23:00 AM »
Hi,

 Thanks 600. Very pro active! This community is great :)

 I have put the intSubstract on the Ecosystem, and I also include a per seconds option as well in that action.

InSubstract

I credited you, but I don't know your real name, so I put "600".

 Bye,

 Jean

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: Float/Int Subtract
« Reply #5 on: January 28, 2015, 09:11:03 AM »
hi, i saw the intSubtract on github with the per second option

and found this very interesting...

so i made this with the int operator.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
// idea by Jean Fabre
// edited by DjayDino
/*--- __ECO__ __ACTION__ ---*/

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Performs math operations on 2 Floats: Add, Subtract, Multiply, Divide, Min, Max.")]
public class IntOperatorPerSecond : FsmStateAction
{
public enum Operation
{
Add,
Subtract,
Multiply,
Divide
}

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The int variable to add / subtract / multiply / divide from and store")]
public FsmInt intVariable;

[RequiredField]
        [Tooltip("The int variable to add / subtract / multiply / divide")]
public FsmInt intOperator;

        [Tooltip("The math operation to perform on the intVariable.")]
public Operation operation = Operation.Add;

[RequiredField]
[UIHint(UIHint.Variable)]

[Tooltip("Used with Every Frame. Adds the value over one second to make the operation frame rate independent.")]
public bool perSecond;

        [Tooltip("Repeat every frame. Useful if the variables are changing.")]
        public bool everyFrame;

float _acc = 0f;

public override void Reset()
{
intOperator = null;
operation = Operation.Add;
intVariable = null;
perSecond = false;
everyFrame = false;
}

public override void OnEnter()
{
DoIntOperator();

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

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

void DoIntOperator()
{

if (!perSecond)
{
switch (operation)
{
case Operation.Add:
intVariable.Value += intOperator.Value;
break;

case Operation.Subtract:
intVariable.Value -= intOperator.Value;
break;

case Operation.Multiply:
intVariable.Value *= intOperator.Value;
break;

case Operation.Divide:
intVariable.Value /= intOperator.Value;
break;
}
}
else
{
switch (operation)
{
case Operation.Add:
DoIntAdd();
break;

case Operation.Subtract:
DoIntSubtract();
break;

case Operation.Multiply:
DoIntMultiply();
break;

case Operation.Divide:
DoIntDivide();
break;
}
}
}

void DoIntAdd()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value += intOperator.Value;
}

}
void DoIntSubtract()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value -= intOperator.Value;
}

}
void DoIntMultiply()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value *= intOperator.Value;
}

}
void DoIntDivide()
{
int _absSub = Mathf.Abs(intOperator.Value);
_acc += ( _absSub* Time.deltaTime);
if (_acc>=_absSub)
{
_acc = 0f;
intVariable.Value /= intOperator.Value;
}

}
}
}

the divide option will end in 0, and will always Round to int value
i am still doubting to take it out or not, but i think its ok

let me know if i should add this , and/or if i should take out the divide option.

friendly greetings,

Dino

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15537
  • Official Playmaker Support
Re: Float/Int Subtract
« Reply #6 on: February 19, 2015, 01:43:41 AM »
Hi,

 I think you should add as much operators as you can :)

Bye,

 Jean

mgluf

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Float/Int Subtract
« Reply #7 on: November 25, 2016, 07:34:37 PM »
Along the same vein, it would make sense for the "FLOAT ADD" action to have a "per second" check box just as there is in the FLOAT SUBTRACT action. Even though this is a simple math fix that can be used by adding negatives.