EdScriptNewbie wrote:
I want to understand what you did.
I'll narrow down the documentation for you:
Quote:
Exception(Message [, What, Extra])Creates an Exception object.
[The What parameter] can be a string or a negative offset from the top of the call stack. For example, a value of -1 sets Exception.What to the current function or subroutine and Exception.Line to the line which called it.
Source: Throw Code:
TheCalledFunction()
TheCalledFunction() {
exception_object := Exception("", -1)
line_number := exception_object.Line
MsgBox %line_number%
}
An Exception object is created which contains the filename and line number of the line that called TheCalledFunction. The
Line field of this object is then retrieved and shown in the MsgBox. % (followed by space) was used in the previous example to indicate that what follows is an expression; this is often necessary because objects can't be used effectively with the %traditional% syntax.
You can just use the expression from my previous example (
Exception("", -1).Line) directly in your function:
Code:
LnN := Exception("", -1).Line - 1 ; And remove LnN from the parameter list.
Quote:
Can I declare my AutoHotkeyDebugLog variable to be global when I first load it (upon starting the script), and thus, know that that never-changing value will always be available for any function?
Not in v1. It mostly works in the current
v2 alpha:
Code:
Func0() {
MsgBox %AutoHotkeyDebugLog% :( ; Current limitation.
}
global AutoHotkeyDebugLog := A_ScriptDir "\Debug.Log"
; Subsequent references in functions need not be declared.
Func0()
Func1()
Func1() {
MsgBox %AutoHotkeyDebugLog%
}
Quote:
Or is there some kind of shorthand other than a variable, that I could use for often-reused items like a file name and path?
You can use a function.
Code:
Func1()
Func1() {
MsgBox % V("AutoHotkeyDebugLog")
}
V(n) {
static AutoHotkeyDebugLog := A_ScriptDir "\Debug.Log"
; Any number of other variables may be added here.
return (%n%)
}
This also works if AutoHotkeyDebugLog is a global variable, since dynamic variable references (a.k.a. double-derefs) don't need global declarations in v1 (but since it's a common cause of confusion, they do in v2).