# How do I create a single line statement with math operations

0 favourites
• 9 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
• Hi,

I want something like VarX1 (MathOpIndex = 1?*:/) VarX2, where MathOpIndex is either 0 or 1, and the value at 0 is *, and the value at 1 is /.

So for example when VarX1 = 3, and VarX2 = 2, and MathOpIndex = 0 then the formula is 3 * 2.

Is there a way to have a single statement to capture this?

Kind Regards,

Jason

• I don't think this is possible, because construct would interpret the * or / as a strings in any way. but you could make a function, and could call it with 3 parameters. than on function you can ask if second parameter is a * or / and make than your math.

``````CallFunction("Math", 3, "*", 2)

OnFunction("Math"):
CompareParameter(1 = "*"): SetVar("Result", "Function.Param(0) * Function.Param(2)")
-or-
CompareParameter(1 = "/"): SetVar("Result", "Function.Param(0) / Function.Param(2)")[/code:1qqrz6yi]``````
• Hi realMantis,

I was hoping for a one line statement, but I guess that's not possible. Thanks for your alternative solution.

• You have to write it like this:

(MathOpIndex = 1) ?VarX1*VarX2 :VarX1/VarX2

• edit:

that was the same answer as previous

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• You have to write it like this:

(MathOpIndex = 1) ?VarX1*VarX2 :VarX1/VarX2

That is a nearly single liner, but you are limited to 2 operations.

• You can do more but it starts to look hairy.

op="+" ? var1+var2:(op="-" ? var1-var2:(op="/" ? var1/var2:(op="*" ? var1*var2:sqrt(-1))))

• damn

• Wow! Impressive statement R0J0hound. It is looking hairy as a single statement. Thanks R0J0hound and realMantis!

• 9 posts