Difference between revisions of "Manual:DIL Manual/isaff()"
Jump to navigation
Jump to search
(XML import of LLM wiki pages) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = isaff() = | ||
| + | '''Function''' (integer). Tells whether a unit carries an affect with a given id. | ||
| + | isaff(u : unitptr, id : integer) | ||
| − | < | + | Looks through the affects on <code>u</code> (spells, poisons, curses and other timed effects added with <code>addaff()</code>) and is TRUE if one of them has the id <code>id</code>. It works on any unit: characters, objects and rooms. |
| − | + | ||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| + | |- | ||
| + | | u || unitptr || The unit to look at. | ||
| + | |- | ||
| + | | id || integer || The affect id, an <code>ID_*</code> constant. | ||
| + | |} | ||
| + | |||
| + | == Returns == | ||
| + | Integer: 1 if <code>u</code> has at least one affect with that id, otherwise 0. If <code>u</code> is null, the result fails: false in an <code>if</code>, so <code>not isaff(null, ...)</code> is true. | ||
| + | |||
| + | == Notes == | ||
| + | * The <code>ID_*</code> constants are in <code>vme/include/vme.h</code> (<code>ID_CORPSE</code>, <code>ID_BLIND_CHAR</code>, <code>ID_INVISIBILITY</code>, <code>ID_CURSE</code>, ...) and <code>vme/include/values.h</code>. There is no <code>ID_BLIND</code>. | ||
| + | * It only tests for the affect, not its strength or time left. <code>getaffects()</code> lists a unit's affects. | ||
| + | * An affect isn't the same as a flag: blindness, for instance, can come from an affect (<code>ID_BLIND_CHAR</code>) or from the flag <code>CHAR_BLIND</code> in <code>charflags</code>, so baselook.zon tests both. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin integer is_blind(u : unitptr); | ||
| + | code | ||
| + | { | ||
| + | if (u == null) | ||
| + | return (FALSE); | ||
| + | return (isaff(u, ID_BLIND_CHAR) or isset(u.charflags, CHAR_BLIND)); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Tells whether a character is blind, from an affect or from the flag, as baselook.zon does. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/addaff()|addaff()]] | ||
| + | * [[Manual:DIL Manual/subaff()|subaff()]] | ||
| + | * [[Manual:DIL Manual/getaffects()|getaffects()]] | ||
| + | * [[Manual:DIL Manual/isset()|isset()]] | ||
Latest revision as of 23:14, 14 November 2026
isaff()
Function (integer). Tells whether a unit carries an affect with a given id.
isaff(u : unitptr, id : integer)
Looks through the affects on u (spells, poisons, curses and other timed effects added with addaff()) and is TRUE if one of them has the id id. It works on any unit: characters, objects and rooms.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit to look at. |
| id | integer | The affect id, an ID_* constant.
|
Returns
Integer: 1 if u has at least one affect with that id, otherwise 0. If u is null, the result fails: false in an if, so not isaff(null, ...) is true.
Notes
- The
ID_*constants are invme/include/vme.h(ID_CORPSE,ID_BLIND_CHAR,ID_INVISIBILITY,ID_CURSE, ...) andvme/include/values.h. There is noID_BLIND. - It only tests for the affect, not its strength or time left.
getaffects()lists a unit's affects. - An affect isn't the same as a flag: blindness, for instance, can come from an affect (
ID_BLIND_CHAR) or from the flagCHAR_BLINDincharflags, so baselook.zon tests both.
Example
dilbegin integer is_blind(u : unitptr);
code
{
if (u == null)
return (FALSE);
return (isaff(u, ID_BLIND_CHAR) or isset(u.charflags, CHAR_BLIND));
}
dilend
Tells whether a character is blind, from an affect or from the flag, as baselook.zon does.