On the second click, the previous value is remembered like a static.
Listvars reports it's not local, static or global.
Code: Select all
GUI()
return
GUI(){
global
Gui , New
Gui , Add , Button , x115 y10 gShowVar , Show local var
Gui , Show , w300 h50
return
ShowVar:
local var
MsgBox % var
var := 1
listvars
return
}
The documentation says we "should" only use statics and globals, but it doesn't say that we can't. If ahk is automatically converting it to a static or global for me, it should show up as such in listvars, or in the documentation.
This whole time I thought I was using local vars, and now I don't know what they are or whether it's causing bugs in my program!https://autohotkey.com/docs/Functions.htm#gosub wrote: A function may contain externally-called subroutines such as timers, GUI g-labels, and menu items. This is generally done to encapsulate them in a separate file for use with #Include, which prevents them from interfering with the script's auto-execute section. However, the following limitations apply:
* Such subroutines should use only static and global variables (not locals) if their function is ever called normally. This is because a subroutine thread that interrupts a function-call thread (or vice versa) would be able to change the values of local variables seen by the interrupted thread. Furthermore, any time a function returns to its caller, all of its local variables are made blank to free their memory.
I am hoping someone can tell me I have overlooked something and that this is not a bug.
Edit: while I'm here, may I ask a clarification about functions. If a function is interrupted by another thread's call to the same function (i.e directly, not from a subroutine within the function), would this mean that when the first thread is handed back execution, it's local vars will be what the interrupting thread left them as? i.e there are NOT two copies of the local var in memory (one for each thread's instance of the function) but rather just the one copy of local var which both threads share. Thanks!