Debugging WMLScript files is very similar to debugging any scripting language. Formal debugging facilities are limited, requiring you, the programmer, to build your WMLScript code incrementally, testing and debugging each block as you work. Use your UP.Browser to test your code each time you add a new block of code.
Working carefully and systematically is also important. Whenever you define a new function, loop, or conditional statement, always build the complete structure of the code block before filling in the implementation details. For example, define a function that is structurally complete, but has no implementation:
function countwords() {
};
Then, build the function one block at a time, adding parameter(s) and conditional statements as you decide how the function is to do its job:
function countwords(str) {
while (str != "") {
//fill in the details and test
//debug code begin
Console.PrintLn("Current string = " + str);
//debug code end
};
};
Another good practice is to test important expressions using the print and printLn functions in the Console library, so that you can see the results of the code as your script executes.
Following these practices helps you isolate syntactical and logical errors much more quickly than if you write a large block of code and then try to test it all at once.
For a more complete discussion of WMLScript debugging, see Chapter 10, Debugging WMLScripts.