Conversion Between Data Types |
Print Previous Next |
Introduction If there are different data types within an expression, they must be converted into the same type. MADRIX Script does those conversions implicitly, but in most times a warning will be displayed in the compiler message box of the Script Editor. It is also possible to do those conversions explicitly writing the destination data type in brackets before the expression, like this: int i = (int)GetSpeed(); //if the speed was 42.8, i is now 42 string s = (string)i; //s now consists of the characters "42"
GetSpeed returns a float value which has to be converted into int before it can be assigned to i. Be aware that the positions after the decimal point are abridged. Afterwards, the numeric value is assigned to i. The following table shows an overview over possible conversions:
Implicit Conversions With Math Expressions If one of the two operands of a math expression is of the type float and the other is of the type int, the int value is converted to float and the expression results in the data type float. If one of the two operands of a math expression is of the type string, the other operand is converted into a string and the expression results in a string. If the conversion is not possible according to the table above, the compiler prints an error and you have to correct the expression. Here are some examples of expressions and their results:
|