if
The if statement creates the branches and switches of your Xtscript
[...] = optional ... = your value
if ...
...
[else
...]
endif
"Nested if's" can be a problem in xtscript ... They do not work and should be avoided
Most of these issues can be overcome using
gotoExample code
Show in textarea<!--parser:xtscript-->
# random number
var $x = call mt_rand $min=1;$max=100
# The basic "if"
if $x > 50
print \$x is more than 50 <hr />
else
print \$x is less than 50<hr />
endif
# Strings can also be compared
var $a=abcdef
var $b=abcdeg
if $a < $b
print '$a' is less than '$b' <hr />
endif
# if's nested like this will not work
var $a=1
var $b=2
if $a == 3
if $b == 2
print \$b equals 2
endif
print \$a equals 3 ?<hr />
endif
# Most of the problems with nested "if's" can be overcome using "goto"
if $a == 3
print \$a equals 3
else
goto @end
endif
if $b == 2
print \$b equals 2
endif
@end
print no output because \$a does not equal 3 so \$b test is skipped
<!--/parser:xtscript-->
Show in textarea Example output
Reload$x is more than 50
'abcdef' is less than 'abcdeg'
$a equals 3 ?
no output because $a does not equal 3 so $b test is skipped