Operators
Operators only appear inside if and while. Two of
them, as and in, are what turn a lookup into
something you can act on.
Comparison
| Operator | Meaning | Example |
|---|---|---|
= or == | equal | if hp = maxhp |
!= | not equal | if hp != maxhp |
< | less than | if hp < 50 |
<= | less or equal | if mana <= 10 |
> | greater than | if weight > maxweight |
>= | greater or equal | if skill 'magery' >= 80 |
and / or / not
and and or join two comparisons.
not inverts a single expression.
if hp < 50 and mana >= 11
cast 'greater heal'
endif
if poisoned or diffhits > 40
potion 'cure'
endif
if not hidden
skill 'hiding'
endif No parentheses, evaluated left to right. You cannot write
(a or b) and c. Nest two ifs instead. The outer one
acts as the and.
Numbers as true/false
An expression that returns a number can be used on its own: 0 is false, anything else is true. This reads nicely and is the idiom most scripts use.
if bandaging // "a bandage is still running"
wait 500
endif
if not bandaging // "I am free to bandage"
hotkey 'Bandage self'
endif
if findtype 3852 self // "I have a heal potion"
potion 'heal'
endif findtype and friends return a serial, and a serial of 0
means “nothing found”, which is why they slot straight into an
if.
as (capture a result)
as stores the result of an expression in a variable, in the same
breath as testing it. Without it you would have to search twice.
if findtype 3852 self as PotsHeal
dclick PotsHeal
endif
Read that as: find a heal potion; if you found one, remember it as
PotsHeal and use it. The variable lives until the script
ends.
if findlayer self righthand as weapon
getlabel weapon weaponlabel
overhead 'wielding {{weaponlabel}}'
endif in (text search)
in is true when the left string appears inside the right one.
Its main use is testing what getlabel brought back.
if findtype 3852 self as pot
getlabel pot potlabel
if 'next usable' in potlabel
sysmsg 'potion is on cooldown'
else
dclick pot
endif
endif
The needle comes first: 'blessed' in itemlabel asks whether
itemlabel contains blessed, not the other way round.