Calling WMLScript Functions
Added 28 Jul 2008
It is straightforward to call a function located in the same WMLScript file. You just need to type the name of the function you want to call, like this:
(Suppose the definitions of main_function(), wmlscript_function1() and wmlscript_function2() are located in the same file.)
function
main_function()
{
...
wmlscript_function1();
wmlscript_function2(arg1,
arg2);
...
}
In the above WMLScript example, wmlscript_function1() and wmlscript_function2() are called from main_function(). Arguments are included inside the parentheses. If the function to be called does not require any arguments, you still need to include the parentheses.
In some programming languages such as C++, the definition of the function to be called must be placed before that of the calling function. This is not required in WMLScript. The order of functions in a WMLScript file does not have any effect. For example, the following WMLScript code:
function
wmlscript_function1()
{
...
}
function
wmlscript_function2(arg1, arg2)
{
...
}
function
main_function()
{
...
wmlscript_variable1 =
wmlscript_function1();
wmlscript_variable2 =
wmlscript_function(arg1, arg2);
...
}
is equivalent to the code below:
function
main_function()
{
...
wmlscript_variable1 =
wmlscript_function1();
wmlscript_variable2 =
wmlscript_function(arg1, arg2);
...
}
function
wmlscript_function1()
{
...
}
function
wmlscript_function2(arg1, arg2)
{
...
}