Difference between revisions of "Manual:DIL Manual/isset()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfisset"></span>
+
= isset() =
−
integer isset ( i : integer , bit : integer )
+
'''Function''' (integer). Tells whether any of some bits are set in an integer.
−
    i : An integer to examine.
 
−
    bit : A set of bits to match.
 
−
    return: TRUE, if bits in 'bit' is set in 'i'.
 
−
    Example: if (isset(self.manipulate, MANIPULATE_TAKE)) ...
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  isset(value : integer, bits : integer)
−
<span id="bfisset"></span>
 
−
integer isset ( i : integer , bit : integer )
 
−
    i : An integer to examine.
 
−
    bit : A set of bits to match.
 
−
    return: TRUE, if bits in 'bit' is set in 'i'.
 
−
    Example: if (isset(self.manipulate, MANIPULATE_TAKE)) ...
 
  
−
---~---~---~---~---~---~---~---~---
+
Most flag fields (<code>flags</code>, <code>charflags</code>, <code>manipulate</code>, <code>openflags</code>, <code>exit_info[dir]</code>, ...) hold several flags as bits of one integer. <code>isset(value, bits)</code> is TRUE (1) when <code>value</code> and <code>bits</code> have at least one bit in common, and FALSE (0) when they have none.
 +
 
 +
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| value || integer || The integer to look at, usually a flag field.
 +
|-
 +
| bits || integer || The bit or bits to look for: a flag constant such as <code>EX_CLOSED</code>, or several joined with <code>&#124;</code>.
 +
|}
 +
 
 +
== Returns ==
 +
Integer: 1 if any bit of <code>bits</code> is set in <code>value</code>, otherwise 0. If either argument fails (for example a field of a null unit), the result fails, and a failed value is false in every test.
 +
 
 +
== Notes ==
 +
* With several bits, <code>isset(u.charflags, CHAR_BLIND | CHAR_HIDE)</code> is true when ''either'' is set. To require all of them, test each: <code>isset(f, A) and isset(f, B)</code>.
 +
* The flag constants are in <code>vme/include/vme.h</code> (<code>UNIT_FL_*</code>, <code>CHAR_*</code>, <code>MANIPULATE_*</code>, <code>EX_*</code>, ...) and <code>values.h</code>.
 +
* <code>set()</code> and <code>unset()</code> change the bits; <code>isset()</code> only reads them.
 +
* A field of a null unit fails, so <code>isset(u.flags, X)</code> and <code>not isset(u.flags, X)</code> behave oddly when <code>u</code> is null: test <code>u == null</code> first.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin integer door_closed(rm : unitptr, dir : integer);
 +
code
 +
{
 +
  if (rm == null)
 +
      return (FALSE);
 +
  if (rm.type != UNIT_ST_ROOM)
 +
      return (FALSE);
 +
  return (isset(rm.exit_info[dir], EX_CLOSED));
 +
}
 +
dilend
 +
</pre>
 +
Tells whether the exit in direction <code>dir</code> of a room is closed.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/isaff()|isaff()]]
 +
* [[Manual:DIL Manual/flags|flags]]
 +
* [[Manual:DIL Manual/charflags|charflags]]
 +
* [[Manual:DIL Manual/manipulate|manipulate]]
 +
* [[Manual:DIL Manual/exit info|exit_info]]

Latest revision as of 23:14, 14 November 2026

isset()

Function (integer). Tells whether any of some bits are set in an integer.

isset(value : integer, bits : integer)

Most flag fields (flags, charflags, manipulate, openflags, exit_info[dir], ...) hold several flags as bits of one integer. isset(value, bits) is TRUE (1) when value and bits have at least one bit in common, and FALSE (0) when they have none.

Parameters

Name Type Meaning
value integer The integer to look at, usually a flag field.
bits integer The bit or bits to look for: a flag constant such as EX_CLOSED, or several joined with |.

Returns

Integer: 1 if any bit of bits is set in value, otherwise 0. If either argument fails (for example a field of a null unit), the result fails, and a failed value is false in every test.

Notes

  • With several bits, isset(u.charflags, CHAR_BLIND | CHAR_HIDE) is true when either is set. To require all of them, test each: isset(f, A) and isset(f, B).
  • The flag constants are in vme/include/vme.h (UNIT_FL_*, CHAR_*, MANIPULATE_*, EX_*, ...) and values.h.
  • set() and unset() change the bits; isset() only reads them.
  • A field of a null unit fails, so isset(u.flags, X) and not isset(u.flags, X) behave oddly when u is null: test u == null first.

Example

dilbegin integer door_closed(rm : unitptr, dir : integer);
code
{
   if (rm == null)
      return (FALSE);
   if (rm.type != UNIT_ST_ROOM)
      return (FALSE);
   return (isset(rm.exit_info[dir], EX_CLOSED));
}
dilend

Tells whether the exit in direction dir of a room is closed.

See also