FANDOM


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() )

StartingConditional Edit

A special type of NWScript conditional includes the scripts that can be used as a "Text Appears When" script within a conversation. These scripts begin execution with an integer-valued function named StartingConditional(), instead of the usual main() function. These scripts behave much like more traditional conditionals in that they choose between courses of action, but instead of actions within a script, they choose between actions within the game (whether or not to display the associated dialog text).

The writing of a StartingConditional() function is the same as the writing of functions that are intended for use in traditional conditionals — it returns zero (or FALSE or a false expression) to indicate that the associated text should not be shown, and non-zero (or TRUE or a true expression) to indicate that the text should be shown.