﻿ Widget Designer > Script Language > Mathematical Expressions

# Mathematical Expressions

Navigation:  Widget Designer > Script Language >

# Mathematical Expressions   Navigation:  Widget Designer > Script Language >

# Mathematical Expressions   When working with variables, you sometimes need to assign its value directly, but other times you might also want to recalculate your variable and use it for other mathematical calculations. You can achieve this with special commands, or with a very easy to understand mathematical syntax.

Obviously, the variable must be of the type integer or double to allow mathematical operations. Integers are rounded to the according whole number. However there is one exception to this rule. Adding letters is actually possible and equals appending letters.
Array variables are supported too. You call an index with square brackets: Variable[Index].

First, the below examples for a relative value assignment work in direct and in common commands. They offer five basic arithmetical operations: addition, subtraction, multiplication, division and exponentiation. The value itself can be a number you choose, another Variable, or a Member Value.

 Scripting options Result varRes Var varRes = 10.5 //creates a LOCAL variable VCreate("varRes",10.5) //creates a GLOBAL variable   varRes += 3 varRes = varRes +3 VAdd("varRes",varRes,3)   varRes -= 1 varRes = varRes -1 VSubtract("varRes",varRes,1)   varRes *= 2 varRes = varRes *2 VMultiply("varRes",varRes,2)   varRes /= 5 varRes = varRes /5 VDivide("varRes",varRes,5)   varRes = varRes ^4 VPow("varRes",varRes,4)   varRes = varRes ^0.5 varRes = varRes ^(1/2) VSqrt("varRes",varRes) 10.5         13.5       12.5       25       5       625     25 Var varRes = "he" VCreate("varText","he")   varRes += "llo" VAdd("varText",varText,"llo") he     hello

For more complex operations, you can use the mathematical syntax as you would write it, see some examples below, for var1 = 5 and var2 = 11.
Remember to assign a suiting type to the variable for the result, e.g. Integer.

 Syntax Result varRes = calculation varRes = var1 + var2   varRes = var1 - 10   varRes = var1 * var2 * 2   varRes = 45 / var1   varRes = var1 ^4 16   5   110   9   625

For more sophisticated mathematical functions, like sinus, logarithms or modulo, please also refer to the chapter Math Object. This object provides several members for further mathematical operations.

## Conditions

If you use those conditions outside of an if-statement, it will return a Boolean value.
Normal condition statements like "is bigger as?" or "equals?" can be combined with AND or OR statements. Please note that those two expressions are not case sensitive.

 Description and Syntax Result Checks if value 1 is bigger than value 2 varRes = (3 > 4)     Checks if value 1 is bigger than or equals value 2 varRes = (3 >= 3)     Checks if value 1 is smaller than value 2 varRes = (3 < 4)     Checks if value 1 is smaller than or equals value 2 varRes = (4 <= 4)     Checks if value 1 equals value 2 varRes = (3 = 4)     Checks if value one does not equal value 2 varRes = (3 != 4) False         True       True         True       False       True Checks if ALL conditions are true varRes = ((3 < 4) AND (3*2 = 6)) varRes = ((3 < 4) AND (3*5 = 7)) varRes = ((3 > 4) AND (3*5 = 7))     Checks if AT LEAST ONE condition is true varRes = ((3 < 4) OR (3*5 = 15)) varRes = ((3 < 4) OR (3*5 = 7)) varRes = ((3 > 4) OR (3*5 = 7)) True False False       True True False