6. Calling WMLScript Functions


6.1. Calling a Function Located in the Same WMLScript File

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)
{
...
}


Previous Page Page 8 of 71 Next Page


Feedback Form (ExpandCollapse)

What do you think about this web page?






(Optional) Please provide us more details. For example, suppose you select option 2 above, can you tell us specifically what information is missing? You can also suggest anything that can help us improve this web page.

(Optional) Your name:

(Optional) Your email address:

Please enter again to confirm:

Due to the amount of messages we received, we may not be able to reply to all messages.