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.