abstract
| - A conditional is an expression used to decide between two possible courses of action. This often means a branching structure (two courses of action that end at the same spot, e.g. an "if" statement), but is also at times be used to describe the controlling expression of a loop (where one course of action ends back at the conditional). NWScript conditionals must have an integer value, with zero being interpreted as "no" or "false" and non-zero values interpreted as "yes" or "true". This may not be clear to beginner scripters, as a conditional will often take the form of a comparison, as in "is this variable equal to 3?" which does not initially appear to be an integer expression. However, the comparison operators (==, !=, <, <=, >, >=) do in fact evaluate to 1 (for truth) or 0 (for falsity). For convenience, NWScript provides two constants — TRUE and FALSE — that can be used as the return value of functions intended for use in conditionals. These constants do not have to be used, though, as such functions can return any expression that could be placed directly in a conditional, and sometimes using such an expression is more convenient than using the constants. In addition, these constants usually do not need to be checked explicitly as they already have values suitable for use in a conditional. (Some BioWare scripts do perform these steps, even when they are unnecessary.) Examples: // Long way to return TRUE or FALSE. if ( nInteger == 3 ) return TRUE; else return FALSE; // Short way to return TRUE or FALSE. return nInteger == 3; // Long way to check a return value for truth. if ( GetIsDawn() == TRUE ) // Short way to check a return value for truth. if ( GetIsDawn() )
|