Difference between revisions of "Manual:DIL Manual/unset()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = unset() = | |
| − | unset ( | + | '''Procedure.''' Turns bits off in an integer variable or field. |
| − | + | ||
| − | + | unset(i : integer, bits : integer) | |
| − | + | ||
| − | < | + | Turns off every bit of <code>bits</code> in <code>i</code> and leaves the other bits as they are. Mostly used on flag fields with the constants from <code>vme.h</code> and <code>values.h</code>: <code>unset(item.openflags, EX_CLOSED)</code> opens a container, <code>unset(u.flags, UNIT_FL_INVISIBLE)</code> makes a unit visible. |
| − | + | ||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| + | |- | ||
| + | | i || integer || An integer variable, or an integer field that can be assigned (<code>u.flags</code>, <code>room.exit_info[dir]</code>, ...). | ||
| + | |- | ||
| + | | bits || integer || The bits to turn off (a mask, not a bit number); join several with <code>|</code>. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * vmc refuses a constant or an expression as <code>i</code>: "Arg 1 of 'unset' not an integer variable". | ||
| + | * On a field of a null unit nothing happens. | ||
| + | * A field this zone may not change (such as <code>pc.level</code> outside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue unset" in the log. | ||
| + | * Only the bits change, nothing else: no messages, and the other side of a door keeps its flags. | ||
| + | * <code>set()</code> turns bits on; <code>isset()</code> tests them. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin open_item(item : unitptr); | ||
| + | code | ||
| + | { | ||
| + | if (not isset(item.openflags, EX_CLOSED)) | ||
| + | { | ||
| + | act("$2n is already open.", A_ALWAYS, self, item, null, TO_CHAR); | ||
| + | return; | ||
| + | } | ||
| + | if (isset(item.openflags, EX_LOCKED)) | ||
| + | { | ||
| + | act("$2n seems to be locked.", A_ALWAYS, self, item, null, TO_CHAR); | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | act("You open $2n.", A_ALWAYS, self, item, null, TO_CHAR); | ||
| + | act("$1n opens $2n.", A_ALWAYS, self, item, null, TO_REST); | ||
| + | unset(item.openflags, EX_CLOSED); | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Opens a container. Adapted from basemove.zon. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/set()|set()]] | ||
| + | * [[Manual:DIL Manual/isset()|isset()]] | ||
| + | * [[Manual:DIL Manual/flags|flags]] | ||
| + | * [[Manual:DIL Manual/openflags|openflags]] | ||
| + | * [[Manual:DIL Manual/exit info|exit info]] | ||
Latest revision as of 23:23, 14 November 2026
unset()
Procedure. Turns bits off in an integer variable or field.
unset(i : integer, bits : integer)
Turns off every bit of bits in i and leaves the other bits as they are. Mostly used on flag fields with the constants from vme.h and values.h: unset(item.openflags, EX_CLOSED) opens a container, unset(u.flags, UNIT_FL_INVISIBLE) makes a unit visible.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | An integer variable, or an integer field that can be assigned (u.flags, room.exit_info[dir], ...).
|
| bits | integer | The bits to turn off (a mask, not a bit number); join several with |.
|
Notes
- vmc refuses a constant or an expression as
i: "Arg 1 of 'unset' not an integer variable". - On a field of a null unit nothing happens.
- A field this zone may not change (such as
pc.leveloutside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue unset" in the log. - Only the bits change, nothing else: no messages, and the other side of a door keeps its flags.
set()turns bits on;isset()tests them.
Example
dilbegin open_item(item : unitptr);
code
{
if (not isset(item.openflags, EX_CLOSED))
{
act("$2n is already open.", A_ALWAYS, self, item, null, TO_CHAR);
return;
}
if (isset(item.openflags, EX_LOCKED))
{
act("$2n seems to be locked.", A_ALWAYS, self, item, null, TO_CHAR);
return;
}
act("You open $2n.", A_ALWAYS, self, item, null, TO_CHAR);
act("$1n opens $2n.", A_ALWAYS, self, item, null, TO_REST);
unset(item.openflags, EX_CLOSED);
return;
}
dilend
Opens a container. Adapted from basemove.zon.