contents.gifindex.gifprev1.gifnext1.gif

pueblo00000000.gif TinTin expressions

TinTin allows the use of expressions in the #if and #math commands. These expressions allow numbers and numeric variables to be compared. This section describes the operators that may be used in expressions.

In addition to the operators described below, the values T and F may be used for true and false, respectively.

Operator Summary

The following operators may be used. They are listed in descending order of precedence.

Operator
Name
Operates on

(
Open parentheses


)
Close parentheses


!
boolean NOT
integers / strings
(unary operator)
_
lowercase
integers / strings
(unary operator)
*
multiplication
integers

/
division
integers

+
addition
integers

+
concatenation
strings

-
subtraction
integers

>
greater than
integers / strings

>=
greater than or equal to
integers / strings

<
less than
integers / strings

<=
less than or equal to
integers / strings

==
equal to
integers / strings

!=
not equal to
integers / strings

&&
boolean AND
integers

||
boolean OR
integers

Expression syntax

Note: The operators are listed below in descending order of precedence. The ‘*’ operator, for example, will occur before the ‘+’ operator.

( ) parentheses

Expressions may be grouped within sets of parentheses. Example:

((4 + $balance) * ($rate / 100)) - 20

! boolean NOT

If an exclamation point occurs before an integer value, it operates as a boolean NOT on the value. (If the value is false (zero), it becomes true (1), otherwise it becomes false.) Example:

!(($val == 10) || ($val > 100))

If the exclamation point occurs before a string value, this operator returns an integer value. For string values, both “0” and the empty string are treated as false. Everything else is treated as true. The operator returns the boolean NOT of the string’s boolean value. For example, the following expressions are all true:

!"0"==1

!""==1

!"test"==0

_ lowercase

If an underscore occurs before a string value, it converts the string to lowercase. This is very useful for doing case-insensitive comparisons. Example:

_"This is a TEST" == _%0

(This operator has no effect on numeric values.)

* multiplication

Multiplication of the left side by the right. Example:

(2 * 1020)

/ division

Division of the left side by the right. Example:

(20 / 4) == 5

+ addition

Addition of the left side and the right. Example:

(4 + 100 + $val + $myval)

+ concatenation

Concatenation of the left side and the right. At least one of the two sides must be a string value, or addition is performed. Example:

#math {newname} {'Name ' + %val}

- subtraction

Subtraction of the right side from the left. Example:

(100 - 90) == 10

> is greater than

Returns true if the left side is greater than the right side. Otherwise returns false. Example:

(100 + 10) > (5 * 20)

"Salamir" > $name

>= is greater than or equal to

Returns true if the left side is greater than or equal to the right side. Otherwise returns false. Example:

(100 + 10) >= 5 * 20 + 10

"Salamir" >= $name

> is less than

Returns true if the left side is less than the right side. Otherwise returns false. Example:

(100 - 10) < (5 * 20)

"Salamir" < $name

>= is less than or equal to

Returns true if the left side is less than or equal to the right side. Otherwise returns false. Example:

(100 - 10) >= 5 * 20 - 10

"Salamir" <= $name

== is equal to

Returns true if the left side is equal to the right side. Otherwise returns false. Example:

100 == $val

"salamir" == _$name

!= is not equal to

Returns true if the left side is not equal to the right side. Otherwise returns false. Example:

10 != 2

"salamir" != _$name

&& boolean AND

Returns true if both the left side and the right side are true (non-zero.) Otherwise returns false. Example:

("salamir" > _$name) && ($flag)

|| boolean OR

Returns true if either the left side or the right side is true (non-zero.) Otherwise returns false. Example:

(5 < 1) || ($flag)

Some rules and warnings

1) Strings in expressions may be quoted using either single or double quotes. Within the string, you can ‘escape’ characters by preceding them with a backslash (use a double backslash to have a single backslash appear.)

Thus, "this is a test" and 'this is a test' are both valid strings and are equal. "Ron's code" is also equal to 'Ron\'s code'.

1) When a variable is used in an expression, the value of the variable is quoted as a string if it has any non-digit characters (except for a '-' as the first character.) Also, the value of the variable is properly escaped within quotes.

1) Comparisons between a integer and a string are done by converting the integer to a string and then performing a lexical comparison. Note that this isn’t the same as an integer comparison. For example, "6" is greater than "123" (‘6’ comes after ‘1’ in sorting order.)

2) You can do case-insensitive comparison using the lowercase unary operator (_). Thus, to compare the values of two variables with regards to case, you could do something like this:

{_$var1 == _$var2}

This operator has no effect on integer values, so you don’t need to worry about whether the variables are integer or string.

5) For string values, both "0" and the empty string are treated as false. Everything else is treated as true.

Also see

#if

#math