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

From DikuMUD Wiki
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:
 +
= islight() =
 +
'''Function''' (integer). Tells whether there is light in a room.
  
 +
islight(u : unitptr)
  
−
<span id="bfislight"></span>
+
Returns <code>TRUE</code> when <code>u</code> is lit and <code>FALSE</code> when it is dark. Give
 +
it a room, usually <code>self.outside</code>: that is how the look and exits commands decide
 +
whether to say ''It is pitch black''. It does not tell whether an object gives light; that is
 +
the [[Manual:DIL Manual/bright|bright]] field.
  
−
'''Function:  '''<i><!--CODE-->integer islight ( u : unitptr )</i><!--ENDCODE-->
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| u || unitptr || The room (or other unit) to test.
 +
|}
  
−
<!--TERM--> '''u'''
+
== Returns ==
−
<!--DEFINITION-->         Unit that you are checking
+
Integer: <code>TRUE</code> or <code>FALSE</code>. It fails when <code>u</code> is null.
−
<!--TERM--> '''returns'''
 
−
<!--DEFINITION-->         ''TRUE' if item is a light, 'FALSE' if it is notway to small', 'to small', 'way to large', 'to large', or null if fits
 
  
−
Simply checks the item to see if it is a light.
+
== Notes ==
 +
* The light is <code>u.light</code> (the unit's own light plus what the light sources in it
 +
  give), plus the <code>light</code> of the unit it is in, plus daylight unless <code>u</code>
 +
  has <code>UNIT_FL_INDOORS</code>: +1 by day, 0 at sunrise and sunset, -1 at night. It is lit
 +
  when the sum is 0 or more.
 +
* So a room with no light setting is always lit indoors and dark outdoors at night. The macros
 +
  in <code>wmacros.h</code> set it: <code>ALWAYS_LIGHT</code> (light 1),
 +
  <code>IN_ALWAYS_DARK</code> and <code>OUT_DARK_NON_NOON</code> (light -1),
 +
  <code>OUT_ALWAYS_DARK</code> (light -2); a torch carried in adds its light.
 +
* On a character it adds the character's own light, the room's and daylight even indoors
 +
  (a character has no <code>UNIT_FL_INDOORS</code>), which says nothing useful: pass the room.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin do_peer(arg : string);
 +
code
 +
{
 +
  if (not islight(self.outside))
 +
  {
 +
      act("It is pitch black.", A_ALWAYS, self, null, null, TO_CHAR);
 +
      quit;
 +
  }
 +
 
 +
  act("You peer around $2n.", A_ALWAYS, self, self.outside, null, TO_CHAR);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
A player command that does nothing in the dark, as <code>direc_dil</code> in basemove.zon
 +
(the exits command) starts.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/light|light]]
 +
* [[Manual:DIL Manual/bright|bright]]
 +
* [[Manual:DIL Manual/setbright()|setbright()]]
 +
* [[Manual:DIL Manual/outside|outside]]

Latest revision as of 23:03, 14 November 2026

islight()

Function (integer). Tells whether there is light in a room.

islight(u : unitptr)

Returns TRUE when u is lit and FALSE when it is dark. Give it a room, usually self.outside: that is how the look and exits commands decide whether to say It is pitch black. It does not tell whether an object gives light; that is the bright field.

Parameters

Name Type Meaning
u unitptr The room (or other unit) to test.

Returns

Integer: TRUE or FALSE. It fails when u is null.

Notes

  • The light is u.light (the unit's own light plus what the light sources in it
 give), plus the light of the unit it is in, plus daylight unless u
 has UNIT_FL_INDOORS: +1 by day, 0 at sunrise and sunset, -1 at night. It is lit
 when the sum is 0 or more.
  • So a room with no light setting is always lit indoors and dark outdoors at night. The macros
 in wmacros.h set it: ALWAYS_LIGHT (light 1),
 IN_ALWAYS_DARK and OUT_DARK_NON_NOON (light -1),
 OUT_ALWAYS_DARK (light -2); a torch carried in adds its light.
  • On a character it adds the character's own light, the room's and daylight even indoors
 (a character has no UNIT_FL_INDOORS), which says nothing useful: pass the room.

Example

dilbegin do_peer(arg : string);
code
{
   if (not islight(self.outside))
   {
      act("It is pitch black.", A_ALWAYS, self, null, null, TO_CHAR);
      quit;
   }

   act("You peer around $2n.", A_ALWAYS, self, self.outside, null, TO_CHAR);
   quit;
}
dilend

A player command that does nothing in the dark, as direc_dil in basemove.zon (the exits command) starts.

See also