Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: elvis75k on September 30, 2014, 12:48:10 PM

Title: Math Expression action
Post by: elvis75k on September 30, 2014, 12:48:10 PM
Well this was already requested in February 2012.
I need this right now and will be a huge lifesaver for me with my current job. As seen in another thread:
...
variable1 = (5 * variable2 + 1/ variable3) - 6        for example
...
Title: Re: Math Expression action
Post by: Lane on September 30, 2014, 01:40:50 PM
You can basically do that.

http://hutonggames.com/playmakerforum/index.php?topic=4066.msg18991#msg18991

But in the format you want it to be, its very complicated. The Conditional Expression action has a .dll you could probably use to get an idea of the complexity of doing something like this.

More info:
http://answers.unity3d.com/questions/695892/inputing-an-equation.html
Title: Re: Math Expression action
Post by: elvis75k on September 30, 2014, 03:14:48 PM
Perfect! Unfortunately the app is for for iOS and that's the BIG problem.

All i need to do is change values in a synoptic.. like an xls sheet:
=$B$4*863/$B$3
In short: i have a number of variables with which you can change the parameters according to the formula.

Pheraps you know of some basic script to use as a placeholder outside PM for variables names and a formula that i can use with get/set property?

I would be immensely grateful!!
Title: Re: Math Expression action
Post by: elvis75k on September 30, 2014, 04:14:33 PM
While waiting for and answer i made this (forget the equation above):

Code: [Select]
public var testA : float;
public var testB : float;
public var testC : float;

function Update ()

{
testA = ( ( Mathf.Ceil ( testB/7f ) -1 ) *7+testC ) *7;
}

Will i die using this solution? I'm not a coder and i thing that i'll get all wrong when need to put into account some if conditions like this: =IF($N$4>53;$N$4/4;"0")

Title: Re: Math Expression action
Post by: Lane on September 30, 2014, 05:49:37 PM
You can make custom actions like that for sure, its just getting the runtime compilation of a written string formula is a completely different matter.

If you have a consistent structure of equation then yeah, just put a bunch of public variables, use them in the equation and you can change them whenever you want. I don't know what you're going for with the conditions thing though.
Title: Re: Math Expression action
Post by: elvis75k on September 30, 2014, 06:15:34 PM
Quote
its just getting the runtime compilation of a written string formula is a completely different matter.
I think i don't understand? Do you mean that on iOS is not possible to swap/change operators on the fly?
Anyways, the custom equations solution is working so far for simple operation.. the conditions i've found in the xls are for clamping values.

To get out of here: do you think that it will be just impossible or only time consuming doing equation with the available actions (math/logic) ?
Thanks for your interest
Title: Re: Math Expression action
Post by: Lane on September 30, 2014, 07:06:51 PM
do you think that it will be just impossible or only time consuming doing equation with the available actions (math/logic) ?
Thanks for your interest

Thats how I do it, its basically all there. If I have something really weird that just takes an annoying amount of actions then I just make a custom action doing that one formula.
Title: Re: Math Expression action
Post by: elvis75k on September 30, 2014, 07:23:11 PM
Fantastico! Will you please show me just one custom action that meet these needs so i can then start making my own?. I wish the action will show Var_A, B and C as an integer input so i can modify these in the FSM without making every time a new action in case the equation is reused. And the possibility to store the result in a new variable.
I hope that you understand my request, already owe you a beer ;)

(Var_A+VarB)/var_C
Title: Re: Math Expression action
Post by: Lane on September 30, 2014, 07:37:37 PM
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Math")]
public class someMath : FsmStateAction
{
[RequiredField]
public FsmFloat varA;

[RequiredField]
public FsmFloat varB;

[RequiredField]
public FsmFloat varC;

[RequiredField]
public FsmFloat storeResult;

        [Tooltip("Repeat every frame.")]
public bool everyFrame;

public override void Reset()
{
varA = null;
varB = null;
varC = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
DoCalc();

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

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

void DoCalc()
{
float result = ( varA.Value + varB.Value ) / varC.Value;
storeResult.Value = result;
}
}
}



Just realized that I used floats instead of Ints, but you get the idea.
Title: Re: Math Expression action
Post by: elvis75k on September 30, 2014, 07:52:42 PM
Thumbs UP!!!!!
Is this no longer in the to do list? (http://hutonggames.com/playmakerforum/index.php?topic=2264.msg9974#msg9974)