As of version 3.3.1, CommandHelper supports traditional operators, in addition to still allowing the pure functional approach. (In fact, the operation functions are still used internally regardless). This allows you to write more readable code, by using more standard symbols instead of only functions. Using operators instead of functions is highly recommended for all new code, though the functional usage will continue to remain supported.
Consider the following perfectly valid code:
This is fairly hard to read, and could quickly get even more complicated and harder to read the more conditions you add. Instead, you can use infix notation now, using standard C/Java operators. The same code as above, converted to the infix notation looks like:
Besides being less typing, it's much easier for a human to read, thanks to the operators. "@var equals 3 and 2 is less than or equal to @var2" as opposed to "and equals @var 3 lte 2 @var2". Using parenthesis is also supported, to force an order of operations:
The following operators are supported, and their order of operations is from top to bottom. Note that all operators are simply converted to the functional notation, so if your code is incorrect, the errors you get will specify function names.
||This is only considered postfix when it comes after an identifier: @i++|
|Unary||! ++ --||
||These are unary operators, they only operate on one identifier|
|Multiplicative||* / %||
|Additive||+ - .||
||If a minus or plus sign is used to denote the sign of a number, it is handled slightly differently, for instance, 2 + -1 does not use any subtraction|
|Relational||< > <= >=||
|Equality||== != === !==||
||There is no operational equivalent for equals_ic|
|Assignment||= += -= *= /= .=||
|| There is no single functional equivalent except for = per se, |
|Array Sub-indices||[ ]||
|| Using square braces allows for array accesses, and in combination with the |
If the array set appears on the right hand side of an assignment, or in a general statement without an assign, it is an
array_get operation. If it appears on the left hand side of an assignment, it is an array_set operation. The brackets
apply to the element just preceeding, for instance with
Note the lack of bitwise operators, which are usually standard in other languages. These are not provided, because the
operators are infrequently used, and may be used for other operations in the future. The functions themselves,
bit_or() still exist, so no functionality has been removed.
Also of note, auto-concatenation always takes lowest priority to all other operations.