script debug if breakpoints not possible

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
Dick99999
Pro Scripter
Posts: 84
Joined: Thu Nov 27, 2008 10:25 am
Location: Netherlands

script debug if breakpoints not possible

Post by Dick99999 » Thu Oct 20, 2016 11:10 am

Sometimes debug mode interferes with script execution. For example when a Firefox add-on dialogue disappears as soon as debug becomes active. Inserting messages is an alternative.
The following builds on that alternative. It collects message-texts and displays that collection at a chosen point(s) in the script. In the mentioned Firefox example, the dialogue does disappear too in this way. However, the script's 'history track' is displayed as collected.
First the subroutine to be inserted in the code:

Code: Select all

//
// ****** Display collected debug message
// Collect message to be displayed by 
//                     let>dbgMsg=%dbgMsg%%CRLF% string of message to be collected
// gosub>showDbgMsg    display collected message and exit
// gosub>showDbgMsg,1  display collected message and return to caller
//
SRT>showDbgMsg
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
Let>MSG_XPOS=0
Let>MSG_YPOS=0
Let>MSG_HEIGHT=750
Let>MSG_WIDTH=1500
MessageModal>dbgMsg
if>showDbgMsg_var_1<>1
   exit>0
endif>
// for next call to work with yes/no exit par
let>showDbgMsg_var_1=
END>showDbgMsg
The sample code below, collects messages in the following way

Code: Select all

if>a=3
   // your code i.e.   pase1Result=OK
   let>dbgMsg=%dbgMsg%%CRLF% message to add to the collection, like case a=%a%
else>
   // your code i.e   pase1Result=Error 
   let>dbgMsg=%dbgMsg%%CRLF% message to add to the collection
endif>
let>dbgMsg=%dbgMsg%%CRLF%Phase 2, starting
if>pase1Result<>OK
   // your code
   let>dbgMsg=%dbgMsg%%CRLF% Phase 2 started, Phase 1 results was %pase1Result%
endif>
And then the actual display at a chosen point(s) in the script to be tested:

Code: Select all

gosub>showDbgMsg
//or
gosub>showDbgMsg,1
// if control should return here after the message display

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts