Difference between revisions of "Manual:DIL Manual/set()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = set() = | ||
| + | '''Procedure.''' Turns bits on in an integer variable or field. | ||
| + | set(i : integer, bits : integer) | ||
| − | < | + | Turns on every bit of <code>bits</code> in <code>i</code> (<code>i := i | bits</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>UNIT_FL_*</code> in <code>u.flags</code>, <code>EX_*</code> in <code>u.openflags</code> and <code>room.exit_info[dir]</code>, <code>CHAR_*</code> in <code>u.charflags</code>, <code>PC_*</code> in <code>pc.pcflags</code>. |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == 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 on; join several with <code>|</code>. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * vmc refuses a constant or an expression as <code>i</code>: "Arg 1 of 'set' 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> or <code>pc.lifespan</code> outside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue set" in the log. | ||
| + | * The field keeps its own size: bits that don't fit in it are lost (<code>u.flags</code> holds 16 bits). | ||
| + | * Only the bits change, nothing else: setting <code>EX_LOCKED</code> on one side of a door doesn't lock the other side (the example does both). | ||
| + | * <code>unset()</code> turns bits off; <code>isset()</code> tests them. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin lock_door(room : unitptr, dir : integer); | ||
| + | external | ||
| + | integer rev_dir@function(i : integer); | ||
| + | var | ||
| + | rev : integer; | ||
| + | code | ||
| + | { | ||
| + | if (not isset(room.exit_info[dir], EX_OPEN_CLOSE)) | ||
| + | return; | ||
| + | |||
| + | set(room.exit_info[dir], EX_CLOSED | EX_LOCKED); | ||
| + | act("*cluck*", A_ALWAYS, room.inside, null, null, TO_ALL); | ||
| + | |||
| + | rev := rev_dir@function(dir); | ||
| + | if (isset(room.exit_to[dir].exit_info[rev], EX_OPEN_CLOSE)) | ||
| + | { | ||
| + | set(room.exit_to[dir].exit_info[rev], EX_CLOSED | EX_LOCKED); | ||
| + | act("*cluck*", A_ALWAYS, room.exit_to[dir].inside, null, null, TO_ALL); | ||
| + | } | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Shuts and locks a door on both sides. Adapted from spells.zon. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/unset()|unset()]] | ||
| + | * [[Manual:DIL Manual/isset()|isset()]] | ||
| + | * [[Manual:DIL Manual/flags|flags]] | ||
| + | * [[Manual:DIL Manual/exit info|exit info]] | ||
| + | * [[Manual:DIL Manual/openflags|openflags]] | ||
| + | * [[Manual:DIL Manual/charflags|charflags]] | ||
| + | * [[Manual:DIL Manual/pcflags|pcflags]] | ||
Latest revision as of 23:23, 14 November 2026
set()
Procedure. Turns bits on in an integer variable or field.
set(i : integer, bits : integer)
Turns on every bit of bits in i (i := i | bits) and leaves the other bits as they are. Mostly used on flag fields with the constants from vme.h and values.h: UNIT_FL_* in u.flags, EX_* in u.openflags and room.exit_info[dir], CHAR_* in u.charflags, PC_* in pc.pcflags.
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 on; join several with |.
|
Notes
- vmc refuses a constant or an expression as
i: "Arg 1 of 'set' not an integer variable". - On a field of a null unit nothing happens.
- A field this zone may not change (such as
pc.levelorpc.lifespanoutside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue set" in the log. - The field keeps its own size: bits that don't fit in it are lost (
u.flagsholds 16 bits). - Only the bits change, nothing else: setting
EX_LOCKEDon one side of a door doesn't lock the other side (the example does both). unset()turns bits off;isset()tests them.
Example
dilbegin lock_door(room : unitptr, dir : integer);
external
integer rev_dir@function(i : integer);
var
rev : integer;
code
{
if (not isset(room.exit_info[dir], EX_OPEN_CLOSE))
return;
set(room.exit_info[dir], EX_CLOSED | EX_LOCKED);
act("*cluck*", A_ALWAYS, room.inside, null, null, TO_ALL);
rev := rev_dir@function(dir);
if (isset(room.exit_to[dir].exit_info[rev], EX_OPEN_CLOSE))
{
set(room.exit_to[dir].exit_info[rev], EX_CLOSED | EX_LOCKED);
act("*cluck*", A_ALWAYS, room.exit_to[dir].inside, null, null, TO_ALL);
}
return;
}
dilend
Shuts and locks a door on both sides. Adapted from spells.zon.