WMLScript Developer's Guide

[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Chapter 10 - Debugging WMLScripts
Section 55 out of 57 total sections , Section 4 out of 4 sections in this chapter


A Debug Example

The following example illustrates the use of Console.printLn. Lines printed in bold face are used for debugging this sample function.

extern function debugtest() {  
    //variables are initialized by an extenral WML  
    var state = WMLBrowser.getVar("state");  
    var action = WMLBrowser.getVar("action");  
    var image = WMLBrowser.getVar("image");  
    var remainingTime =         Lang.parseInt(WMLBrowser.getVar("remainingTime"));  
    var done = 0;  
    var useanimation = 1;  
    var nexturl = "invalid.wml";  
    //********begin debug code: check all input variables  
    Console.printLn("********begin fsm*********");  
    Console.printLn("State:" + state);  
    Console.printLn("Action:" + action);  
    Console.printLn("Image:" + image);  
    Console.println("Time:" + remainingTime);  
    //********end debug code  
 
    if (action == "timer") {  
        remainingTime = remainingTime - 2;  
        WMLBrowser.setVar("remainingTime", remainingTime);  
 
//Example continues on the next page  
 
        if (remainingTime > 0) {  
            //If animation is on, replace image  
            if (useanimation == 1) {  
 
                if (image == "image1.bmp") {  
                    Console.printLn("setVar: image2.bmp");  
                    WMLBrowser.setVar("image","image2.bmp");  
                }  
                else if (image == "image2.bmp") {  
                    Console.printLn("setVar: image1.bmp");  
                    WMLBrowser.setVar("image","image1.bmp");  
                }  
 
                Console.println("end of animation -                     debugtest()");  
 
                //********begin debug code  
                Console.printLn("**animation refresh**");  
                image = WMLBrowser.getVar("image");  
                //display image file name  
                Console.printLn("Image:" + image);  
                remainingTime =
                    WMLBrowser.getVar("remainingTime");  

                  //display time remaining  
                Console.printLn("Remaining Time:" +
                     remainingTime);  

                //********end debug code  
 
                done = 1;  
                //Console.printLn("******done*******");  
                WMLBrowser.refresh();  
                //display current card name  
                Console.printLn("WMLBrowser.getCurrentCard:"
                     + WMLBrowser.getCurrentCard());  

            } // useAnimation==1  
 
        } // remaining Time > 0  
          
    } // action==timer  
} //debugtest()  

This example demonstrates how to use Console.printLn to display all of the input variables set by an associated WML and script status as the function executes. Use this example as a guide to using Console.printLn to debug your scripts.


[Cover] [Previous Section] [Next Section] [Index]


Part Number DKDS-41-002, UP.SDK Release 4.1, December 2000

Copyright © 1994-2000 Openwave Systems Inc. All rights reserved.
Please send comments and questions to sdk-doc-comments@openwave.com.