if
The if
script command is used to conditionally execute or skip the next command block.
Usage
if <needle*> iselement <haystack*>
if <needle*> isin <haystack*>
if <stringa*> isclass <stringb*>
if <entity*> [!]isgroup <group*>
if <entity*> istype <type*>
if <stringa*> (==|!=) <stringb*>
if <numbera*> (==|!=|<=|<|>=|>) <numberb*>
Context: For self
Parameters:
Parameter | Type | Description |
---|---|---|
needle |
string or variable |
String or string variable to search |
haystack |
string or variable |
String or string variable to search in |
entity |
entity or variable |
Entity or string variable containing an entity ID to check |
group |
string or variable |
Group or string variable to check for |
type |
string or variable |
Equipment type or string variable to check for |
stringa |
string or variable |
A string or string variable |
stringb |
string or variable |
A string or string variable |
numbera |
number or variable |
A number or number variable or int variable |
numberb |
number or variable |
A number or number variable or int variable |
Variable parameters
All parameters of the will be dereferenced if they look like a variable but the variable type must match the operator and both left and right parameter must be of the same type (int
is considered the same as number
for this). Non-variable parameters on the left side of the operator are considered to be a string
for the iselement
, isin
, isclass
, isgroup
, !isgroup
and istype
and a number
for the ==
, !=
, <=
, <
, >=
and >
operators. Non-variable parameters on the right side of the operator are considered to be of the same type as the left side parameter.
Operators
iselement
Interpret <haystack*>
as a space-separated list and execute the next block if and only if <needle*>
is contained in that list.
isin
Execute the next block if and only if <needle*>
is a substring of <haystack*>
.
isclass
Execute the next block if and only if <stringa*>
is a substring of <stringb*>
or <stringab>
is a substring of <stringa*>
. This means that the if isclass
is equivalent to chaining two if isin
with swapped parameters.
isgroup
Execute the next block if and only if <entity*>
exists and is in the group given by <group*>
.
!isgroup
Execute the next block if and only if <entity*>
exists and is not in the group given by <group*>
.
istype
Execute the next block if and only if <entity*>
exists and has the equipment type given by <type*>
. The value for <type*>
can be one of the arguments accepted by setobjecttype
.
==
and !=
Execute the next block if and only if the two parameters are equal. Comparison is done as string
or number
depending on the type of the parameters.
<=
, <
, >=
and >
Execute the next block if and only if <numbera*>
is less than or equal, less than, greater or equal, or greater than <numberb*>
respectively.