Manual:DIL Manual/set()
Jump to navigation
Jump to search
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.