user defined functions
Functions are defined using the function statement
[...] = optional ... = your value
function_name[ $first_var=...; $more_vars=... ; $last_var=...]
[...]
endfunction
[var $... = ]call function_name[ $first_var=...; $more_vars=... ; $last_var=...]
Notes
Functions can be defined in the current script
or in a
.xt file stored locally or anywhere on the web.
Functions can also be called from html
The Function must be defined in a Xtscript on the same page
or
included from elsewhere
<xt:call function="..." first_var="..." more_vars="..." last_var="..."/>
or like this
<xt:call function="..." args="$first_var=...;$more_vars=...;$last_var=..." /> Example code
<!--parser:xtscript-->
# A simple function
function my_function $var_1=1;$var_2=100;
var $num = call mt_rand $min=$var_1;$max=$var_2;
return $num
endfunction
#Call function with default arguments
print Direct<br />
call my_function
print <br />
#Call function with new arguments
call my_function $var_1=200;$var_2=300
print <hr />
# Include local .xt file containing a function
print Local<br/>
include /manual/basics/examples/filename.xt
# Call included function
call @my_other_function $var_1=500;$var_2=1000
print <hr />
# Include external .xt file containing a function
print External<br />
include your_site.xtgem.com/function.xt
# Call included function
call your_site.xtgem.com@someones_function $var_1=2000;$var_2=3000
<!--/parser:xtscript-->
<hr />Html direct <br/>
<xt:call function="my_function" var_1="5000" var_2="6000"/>
<hr />Html local <br/>
<xt:call function="@my_other_function" var_1="6000" var_2="7000"/>
<hr />Html external <br/>
<xt:call function="your_site.xtgem.com@someones_function" var_1="7000" var_2="8000"/>
Show in textareaExample output
ReloadDirect
47
249
Local
705
External
2155
Html direct
5958
Html local
6244
Html external
7356