L3DT users' wiki
Large 3D terrain generator

if/else/endif

The if operator switches execution of the script depending on the value of a boolean argument:

  • If the argument is true, control passes to the line following the if statement.
  • If the argument is false, control passes to the line following the next else or endif statement.

The function of if, else and endif are demonstrated below:

// create a new boolean value, and set it to true
bool b
set b true

// test value of 'b', and echo value to event log
if b
  echo "b is true!"
else
  echo "b is false!"
endif

The output of which is:

b is true!

Closure and nesting

Each if statement must be closed by a matching endif statement, and may contain one else statement. Chains of if/else statements must be nested (unlike C/C++), as shown below:

// create a new string value, and use it to compare in if/else chain
string s
set s "goodbye"

// test value of 's', and reply accordingly
if <zs:not <zs:strcmp s "hello">>
  echo "Hello to you too!"
else
  if <zs:not <zs:strcmp s "goodbye">> // note if is nested inside else
    echo "Farewell!"
  endif
endif

The output of which is:

Farewell!
 
plugins/general/zeoscript/reference/flow/if_else_endif.txt · Last modified: 2017/08/31 04:19 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki