Discuss this page

if

See if at Xelerus

Syntax (if condition exp1 [exp2]) → value
Arguments condition: anything that evaluates to Nil or non-Nil
exp1: an expression that gets evaluated if 'condition' evaluates to non-Nil (if it is 'true')
[exp2]: an optional expression that gets evaluated if 'condition' evaluates to Nil (i.e. is 'false')
Returns value: Whatever the expression that gets invoked returns
Category control structure
Description Basic branching function. Allows executing something only if a certain condition is met. A fundamental thing.

Unless condition explicitly evaluates Nil, the function considers it to be true. This works for any Nil value in any data type: error, function, int32, list, primitive, string, struct, true. Even a list containing only Nil values is considered true since the list itself is not equal to Nil. This behavior is equivalent to the following code:

(neq condition Nil)

Example

(if (eq (sysGetNode) "SE")
 
    (objSendMessage gPlayerShip Nil "We are still in Eridani system")
 
    (objSendMessage gPlayerShip Nil "We are on the journey to the core")
 
)

Return to Functions list