O'Reilly logo

Learning WML, and WMLScript by Martin Frost

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Variables

WMLScript provides only local variables and access to the WML variables (which are always string-valued) from the browser context. There are no global variables, and there is no way to have any values persist from call to call. When a function returns, all its variables are lost.

A WMLScript variable can take a value of any of the five datatypes, including invalid. Variables are declared with the var statement. Any number of variables may be specified, separated by commas such as:

var foo;
var x, y, z;
var a, b, c, d, e, f, g, h, i, j;

Variables must be declared before use, so for example the following is incorrect:

function foo ( )
{
    wibble = 2;
    var wibble;
}

All variables are implicitly initialized to the empty string, "". If some other initial value is required, an optional initializer may be included with the declaration:

var foo = 17, bar = 42;

This is completely equivalent to:

var foo, bar;
foo = 17;
bar = 42;

This means that the usual pattern of a WMLScript function is to first read variables out of the WML browser context, then process those values in some way, then write back new values to the context, and run a task (usually either a <refresh> or a <go>). For an illustration, see Example 10.1. The updated display reflects the new values of variables. I will return to browser variables in later chapters.

Example 10-1. Outline of a Function Called from WML

extern function called_from_wml ( ) { /* First read variables from browser context. * These could also be passed in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required