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

Get help using Construct 2

### » Tue Jun 28, 2016 6:55 am

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
Last edited by jbar6381 on Tue Jun 28, 2016 8:21 am, edited 1 time in total.
B
9
S
2
Posts: 18
Reputation: 619

### » Tue Jun 28, 2016 7:04 am

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.

Code: Select all
`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)")`
Last edited by Kitsune42k on Tue Jun 28, 2016 3:56 pm, edited 1 time in total.
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

### » Tue Jun 28, 2016 9:23 am

Hi realMantis,

I was hoping for a one line statement, but I guess that's not possible. Thanks for your alternative solution.
B
9
S
2
Posts: 18
Reputation: 619

### » Tue Jun 28, 2016 3:36 pm

You have to write it like this:
(MathOpIndex = 1) ?VarX1*VarX2 :VarX1/VarX2
B
101
S
39
G
134
Posts: 5,590
Reputation: 85,518

### » Tue Jun 28, 2016 3:52 pm

edit:
that was the same answer as previous
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Tue Jun 28, 2016 3:56 pm

R0J0hound wrote: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.
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

### » Tue Jun 28, 2016 4:16 pm

You can do more but it starts to look hairy.
op="+" ? var1+var2:(op="-" ? var1-var2:(op="/" ? var1/var2:(op="*" ? var1*var2:sqrt(-1))))
B
101
S
39
G
134
Posts: 5,590
Reputation: 85,518

### » Tue Jun 28, 2016 4:18 pm

damn
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

### » Wed Aug 17, 2016 11:34 am

Wow! Impressive statement R0J0hound. It is looking hairy as a single statement. Thanks R0J0hound and realMantis!
B
9
S
2
Posts: 18
Reputation: 619