Numeric expressions can be parsed. If a parameter is set to an expression, the value of the corresponding global variable is obtained and a floating value is returned after calculation. The global variable in use can be monitored in real time. When the value of the global variable changes, the value of the expression is updated in real time. In addition, a series of functions is supported, such as logical operation, mathematical calculation, and string operation functions. In a numeric expression, only functions supported by numeric expressions, numeric variables, numbers, and expressions that consist of them can be nested. If the value parsed from a numeric expression contains more than seven digits, the precision may be affected. It is recommended that the value contain no more than seven digits. In other functions, parameters that are of the number type and support expressions can call the numeric expression parsing function.
Control image visibility. For example, tap the screen several times to switch between wallpapers, or design a scrollable position animation to achieve the panoramic effect.
Play or stop a video when certain conditions are met.
The add, minus, multiply, divide, and modulo operations, parentheses, and functions are supported.
Add, minus, multiply, divide, and modulo operations: + - * / % Supported functions: sin, cos, tan, asin, acos, atan, sqrt, abs, min, and max (see the following table) Arrays: An example is #number[expression]. The index can be parsed using an expression. Global or custom variables: An example is #screen_width.
Expression | Description |
|---|---|
digit(x) | Obtains a digit from a specified number. The sequence number of the digit to be obtained is calculated from right to left and starts from 1. For example, the return value of digit(12345, 2) is 4 and that of digit(12345, 1) is 5. |
round(x) | Rounds off an input value. If the input value is negative and its decimal part equals to 0.5 or smaller, round off the value to the larger integer; otherwise, round off the value to the smaller integer. For example, the return value of round(4.5) is 5 and that of round(–4.5) is –4. |
int(x) | Abandons the decimal part. For example, the return value of int(4.5) is 4 and that of int(–4.5) is –4. |
rand() | Obtains a random value ranging from 0 to 1. The return value is of the float type. |
int(rand()*a+b) | Obtains a random integer ranging from b to b + a. |
sqrt(x) | Squares a single value. For example, the return value of sqrt(2) is 4. |
eq(x,y) | Checks whether x is equal to y. If yes, 1 is returned. If no, 0 is returned. Both x and y can be expressions. This rule also applies to the following judgment expressions. |
ne(x,y) | Checks whether x is unequal to y. If yes, 1 is returned. If no, 0 is returned. |
ge(x,y) | Checks whether x is greater than or equal to y. If yes, 1 is returned. If no, 0 is returned. |
gt(x,y) | Checks whether x is greater than y. If yes, 1 is returned. If no, 0 is returned. |
le(x,y) | Checks whether x is less than or equal to y. If yes, 1 is returned. If no, 0 is returned. |
lt(x,y) | Checks whether x is less than y. If yes, 1 is returned. If no, 0 is returned. |
isnull(x) | Checks whether a variable is empty. If yes, 1 is returned. If no, 0 is returned. In this expression, x is a global variable. For example, isnull(#var) or isnull(@var) is used to check whether var has a value. |
not(x) | Checks whether x is equal to 0. If yes, 1 is returned. If no, 0 is returned. |
ifelse(x,y,z) | Checks whether x is greater than 0. If yes, y is returned. If no, z is returned. |
ifelse(x1,y1,x2,y2,...,z) | if x1 > 0 return y1; else if x2 > 0 return y2; ... ; else return z Checks whether xn is greater than 0, where n starts from 1. If yes, yn is returned. If no, the judgment continues until a condition is met. If none of the conditions are met, z is returned finally. At least three values x1, y1, and z are required to complete the judgment loop. If no value is found in any of the judgment conditions, the last value is returned. |
pow(x,y) | Raises x to the power of y. For example, the return value of pow(2,3) is 8. |
len(number) | Counts digits in a specified number. For example, the return value of len(1234) is 4 and that of len(-123.123) is 6. |
strIsEmpty(str) | Checks whether a character string is empty. If yes, 1 is returned. If no, 0 is returned. String expressions are supported. |
strIndexOf(str1,str2) | Returns the position index of the first str2 in str1. The index value starts from 0. If str2 does not exist in str1, –1 is returned. String expressions are supported. |
strLastIndexOf(str1,str2) | Returns the position index of the last str2 in str1. The index value starts from 0. If str2 does not exist in str1, –1 is returned. String expressions are supported. |
strContains(str1,str2) | Checks whether str1 contains str2. If yes, 1 is returned. If no, 0 is returned. String expressions are supported. |
sin(x) | Returns the sine of x, in radians. |
cos(x) | Returns the cosine of x, in radians. |
asin(x) | Returns a value ranging from –pi/2 to pi/2 if x ranges from –1 to 1, and returns 0 if the absolute value of x is greater than 1. |
acos(x) | Returns a value ranging from –pi/2 to pi/2 if x ranges from –1 to 1, and returns 0 if the absolute value of x is greater than 1. |
tan(x) | Returns the tangent of x. If the absolute value of x is close to a multiple of pi/2, an incorrect value may be returned due to the precision problem. |
atan(x) | Returns the arc tangent of x. |
sqrt(x) | Returns the square root of x. If the value of x is negative, 0 is returned. |
abs(x) | Returns the absolute value of x. |
min(x, y) | Returns the smaller value between x and y. |
max(x, y) | Returns the larger value between x and y. |
Example 1: Use an expression for calculation. In this example, if the value of t1 is 3, the return value is 4, which is calculated as follows: (10 + 2 x 3)/4.
<Var name="t1" expression="3"/> <Text x="50" y="10" size="30" format="(10+2*#t1)/4: %d" paras="(10+2*#t1)/4" />
Example 2: Use a mathematical formula for calculation. In this example, the sine, cosine, and tangent values of 1.5 are returned.
<Text x="50" y="100" size="30" format="sin(1.5),cos(1.5),tan(1.5): %d,%d,%d" paras="sin(1.5)*100,cos(1.5)*100,tan(1.5)"/>
Example 3: Check whether 1 is greater than 0. In this example, 1 is returned.
<Text x="50" y="1550" size="30" format="gt(1,0): %d" paras="gt(1,0)"/>
Example 4: Check whether 1 is greater than 0. In this example, 2 is returned.
<Text x="650" y="1000" size="30" format="ifelse(1,2,3):%d" paras="ifelse(1,2,3)"/>
Example 5: Determine the position where the first e is displayed in the string "hello". The index value starts from 0. Therefore, 1 is returned in this example.
<Var name="a" expression="hello" type="string"/> <Text x="650" y="1350" size="30" format="strIndexOf(@a,'e'):%d" paras="strIndexOf(@a,'e')"/>
Example 6: Nest a numeric expression in another numeric expression to check whether the position index of the first e in the string variable a is less than 3. If so, 1 is returned.
<Var name="a" expression="hello" type="string"/> <Text x="650" y="1350" size="30" format="lt(strIndexOf(@a,'e'),3)" paras="lt(strIndexOf(@a,'e'),3)"/>