If
if runs the line or block after it only when the condition is true; otherwise the script skips it. An
else after it runs instead when the condition is false.
Parameters
Section titled “Parameters”| Parameter | Meaning |
|---|---|
condition |
An expression, such as %a > %b or #FindCnt = 0. |
lines |
Optional. Without a block, how many of the following lines belong to the if. Default: 1. |
When is it true?
Section titled “When is it true?”The condition is true only when it evaluates to #true, which is -1. Comparisons
(=, <, in, …) produce -1 or 0, and &&, || and ! combine those as expected.
A plain value is not turned into true or false: if 1 and if yes are both false, and if %flag is
true only when %flag holds #true. See #True and #False.
One line, a block, or a number of lines
Section titled “One line, a block, or a number of lines”Without a block, the if controls only the next line:
set %a 100set %b #randomif %a > %b display ok a is bigger than belse display ok a is equal to or less than bhaltTo control several lines, put them in a block:
set %a 100set %b #randomif %a > %b{ display ok a is bigger than b set %b %a}else{ display ok b is equal to or bigger than a set %a %b}haltA block is a { line, the lines to run, and a matching } line. The { has to be the very next line:
a blank line or a comment in between means only that line belongs to the command, and the block after it
runs every time. Braces go on lines of their own.
The older form gives the number of lines instead of a block. Every script line counts, blank lines and comments included:
set %a 100set %b #randomif %a > %b 2 display ok a is bigger than b set %b %aelse 2 display ok b is equal to or bigger than a set %a %bhaltNegating a condition
Section titled “Negating a condition”! reverses only the value right after it, before any comparison is made. So if ! %var = world does
not mean “if %var is not world”: it compares ! %var with world, which is never equal. Use <>, or
put the condition in parentheses:
set %var helloif %var <> world display ok shown: hello is not worldif ! ( %var = world ) display ok shown as wellif ! %var = world display ok never shownhaltNesting
Section titled “Nesting”if and else can be nested to any depth:
set %a #random % 3 + 1if %a = 1 display ok Oneelse{ if %a = 2 display ok Two else display ok Three}haltSee also
Based on the EasyUO wiki, edited for EasyUO Reforged. This text is available under the GNU Free Documentation License 1.2.