Difference between revisions of "Manual:DIL Manual/islight()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = islight() = | |
| + | '''Function''' (integer). Tells whether there is light in a room. | ||
| − | + | islight(u : unitptr) | |
| − | + | 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. | |
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | u || unitptr || The room (or other unit) to test. | ||
| + | |} | ||
| − | + | == Returns == | |
| + | Integer: <code>TRUE</code> or <code>FALSE</code>. It fails when <code>u</code> is null. | ||
| − | + | == 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 thelightof the unit it is in, plus daylight unlessuhasUNIT_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
inwmacros.hset it:ALWAYS_LIGHT(light 1),IN_ALWAYS_DARKandOUT_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.