 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Tue Oct 02, 2007 12:25 pm Post subject: |
|
|
| Quote: | | is there an alternate to actual `n to designate end of line ??? | What for?
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3626 Location: Belgrade
|
Posted: Tue Oct 02, 2007 1:20 pm Post subject: |
|
|
I use this function for debuging for long time. It can output 3 different ways
| Code: | ;------------------------------------------------------------------
; Function: Trace
; Debug helper
;
; Remarks:
; There are 3 trace types: _f_, _d_, _t_
; _f_ - string will be appended at the end of the file trace.log
; _d_ - string will be ouput using OutputDebug
; _t_ - string will be output using Tooltip. This type has 1 parameter
; which is number of history lines to keep
;
; By default _Trace() works in _f_ mode. To change the mode call function
; with first parameter specifying new mode:
;> Trace("_t_", 4) ;switch to tooltip mode, use 4 history lines
;
; You can enter up to 6 parameters. They will be displayed on single line
; between "|" separator
;
; Set global variable _trace to false to desable tracing
;
; Example:
;> _trace := true, Trace("_t_") ;set at start of the script
;> Trace(1, "some data", 3, 4, 5, 6)
;
Trace( pMsg0, pMsg1="", pMsg2="", pMsg3="", pMsg4="", pMsg5="", pMsg6="" ){
local msg, time
static type :="_f_", ttip, tcnt=1
If !_trace
return
time := A_Hour ":" A_Min ":" A_Sec "," A_MSec " [" A_TickCount "]" " "
if pMsg0 in _d_,_f_,_t_
{
type := pMsg0
if type = _t_
if pMsg1 is Integer
tcnt := pMsg1
return
}
msg := pMsg0
loop
if (pMsg%A_Index% != "")
msg .= " | " pMsg%A_Index%
else break
if (type = "_d_") {
OutputDebug, %msg%
return
}
if (type = "_f_") {
FileAppend, %time%%msg%`n, %A_ScriptDir%\trace.log
return
}
if (type = "_t_") {
if (tcnt > 1) {
ttip := msg "`n" ttip
StringReplace, ttip, ttip, `n, `n, UseErrorLevel
if (ErrorLevel = tcnt)
ttip := SubStr(ttip, 1, InStr(ttip, "`n", false, 0)-1)
msg := ttip
}
Tooltip, %msg%, 0, 0, 19
return
}
} |
_________________
 |
|
| Back to top |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 142
|
Posted: Tue Oct 02, 2007 4:09 pm Post subject: |
|
|
| Joy2DWorld wrote: | small suggests like:
why not call it DEBUG() ? | print and println are just ancient names borrowed from other languages. You can change it to whatever suits you.
| Joy2DWorld wrote: | maybe include an optional Debug(text = "", pause = 0) {
option so that if pause // msgbox or pause ?? | Possibly could add that, but if you want a message box, why not just use the message box command?
| Joy2DWorld wrote: | and... maybe
a global DEBUGon? var... | I personally would probably not use this, but you could write a debug function to include with the original script that implements some of these features you want:
| Code: | Debug(str, pause = 0) {
global DebugOn
if !DebugOn
return
if pause
MsgBox, %str%
else
Print(str)
} |
Last edited by Xander on Tue Oct 02, 2007 4:22 pm; edited 1 time in total |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Tue Oct 02, 2007 4:14 pm Post subject: |
|
|
| Quote: | Debug(str, pause = 0) {
if !DebugOn | likely needs a global dec,
| Quote: | Debug(str, pause = 0) {
global DebugOn?
if !DebugOn?
|
and purpose of msgbox/pause is to allow freezing the script (where you choose), for debug help.. (like single step type thing),
and... reason to keep it in debug() is that with one global var set.. (at start of script) you can turn on debugging and off.... _________________ Joyce Jamce |
|
| Back to top |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 142
|
Posted: Tue Oct 02, 2007 4:23 pm Post subject: |
|
|
| Joy2DWorld wrote: | | Quote: | Debug(str, pause = 0) {
if !DebugOn | likely needs a global dec |
That is correct, correction has been made, thanks. |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Tue Oct 02, 2007 4:57 pm Post subject: |
|
|
I use message boxes, tool tips and ListVars for debugging. But this looks nice, thanks. _________________
RegExReplace("irc.freenode.net/ahk", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2") |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Oct 03, 2007 12:47 am Post subject: |
|
|
| lexikos wrote: | | Quote: | | is there an alternate to actual `n to designate end of line ??? | What for?  |
'quickhand' code notation... ex. "funct(x) { // if x < 0// return "Sorry!" // }"
instead of
funct(x) {
if x <0
return "Sorry!"
} _________________ Joyce Jamce |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Oct 03, 2007 12:53 am Post subject: |
|
|
additional thought.. | Code: | Debug(text = "",version = 0, pause = "") { ; use Debug? = 1 or Debug? = V{vers#} // if no vers # shows with all vers, pause for msgbox pause
global Debug?
static create, DebugOutput, vers
if !Debug?
return
if pause = 1
pause := text
if !create {
create = 1
if regexmatch(Debug?,"i)\bV\s*(?<S>\d+(\.\d+)?)",ver)
Debug? := regexreplace(Debug?,"i)\bV\s*[\w.]+")
if (Debug? = 1) or (debug = "")
Debug? = w500 r4
if !regexmatch(Debug?,"i)w\s*(?<E>\d+)",fromsid)
fromside = 500
gui, 98:default
; Gui, -Caption ; leave on so can change size, etc..
Gui, Margin, 0, 0
gui, font, Cred S11, Veranda
gui, color, ,EFEFD5
Gui, Add, Edit, %Debug?% vDebugOutput ; ie, debug contains w500 r4 or whatever!
x := A_ScreenWidth - #(fromside)
Gui, Show, +resize +maximizebox NoActivate x%x% y%y%
gui, 1:default
}
if (version and vers and (version < vers))
return |
idea to make the debug() VERSION based, so
debug("var PPr looks like :" PPr,2) for ver2
debug( a_linenumber "> " otherfunc(xx),2.1)
and setting at script top, Debug? = v2.1
so all lower version debugs are auto-killed....
ie... only get debugs you need for RELEVANT bug... type thing..
edit: (\.\d+)? added to \d+ to allow for dec'd numerics of vers... actually could just as well be non-numeric but... whatever...floats... _________________ Joyce Jamce
Last edited by Joy2DWorld on Wed Oct 03, 2007 4:13 pm; edited 2 times in total |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Wed Oct 03, 2007 1:37 am Post subject: |
|
|
| Joy2DWorld wrote: | | lexikos wrote: | | Quote: | | is there an alternate to actual `n to designate end of line ??? | What for?  |
'quickhand' code notation... ex. "funct(x) { // if x < 0// return "Sorry!" // }"
instead of
funct(x) {
if x <0
return "Sorry!"
} | Ah, no. I'm sure it has been suggested before, though. The closest you could come would be using comma , to put multiple expressions on the same line, and using ?: instead of if. | Code: | funct(x) {
return x<0 ? "Sorry!" : ""
} | The following isn't possible, since return is a command: | Code: | | x += 1, return x<0 ? "Sorry!" : "" | ('return' is interpreted as a variable.) |
|
| Back to top |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 142
|
Posted: Wed Oct 03, 2007 3:11 am Post subject: |
|
|
| Joy2DWorld wrote: | idea to make the debug() VERSION based, so
[...] |
Sounds like you may want to go with one of the other debugging options posted. No need to reinvent the wheel
I am going to keep the OP version as is... the last thing I want is a buggy debugger  |
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 422 Location: Galil, Israel
|
Posted: Wed Oct 03, 2007 4:40 pm Post subject: |
|
|
@Xander,
thanks again for GREAT tool !!!!
have been using with version based notices, and *W*W* wow... it sure makes life easier... as many private msgs as desired ... then when have nailed down the issue, simply upgrade the version # tag at top of script and... silence...
no external progs to open... all clean and simple! _________________ Joyce Jamce |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|