- function related to global variable not working
- check help page and make it working
- play with the code for further understanding < I'm here now
The part I have problem is a function record and display user click records
The working code after I fixed it:
Code: Select all
#SingleInstance Force
#Requires Autohotkey v2.0+
; coords [{X1,Y1},{X2,Y2}...]
global ClickPosRecords := []
^LButton::
{
global ClickPosRecords
MouseGetPos(&x, &y)
if(!IsSet(ClickPosRecords)){
ClickPosRecords := []
}
ClickPosRecords.Push({X:x, Y:y})
TagCoords(ClickPosRecords)
}
TagCoords(coords){
global ClickPosRecords
tagContent := "Coords: " . ClickPosRecords.length . "`n"
for coord in ClickPosRecords {
tagContent .= coord.x . "," . coord.y . "`n"
}
ToolTip(tagContent)
}
Then I found something I don't understand, as the document says, if you don't declare the global variable first before assigning it, it's treated as local variable
But this local variable still works like a global variable
Code below removed declaration of global records, but it still works, why?
Code: Select all
#SingleInstance Force
#Requires Autohotkey v2.0+
; coords [{X1,Y1},{X2,Y2}...]
global ClickPosRecords := []
^LButton::
{
; global ClickPosRecords
MouseGetPos(&x, &y)
; if(!IsSet(ClickPosRecords)){
; ClickPosRecords := []
; }
ClickPosRecords.Push({X:x, Y:y})
TagCoords(ClickPosRecords)
}
TagCoords(coords){
; global ClickPosRecords
tagContent := "Coords: " . ClickPosRecords.length . "`n"
for coord in ClickPosRecords {
tagContent .= coord.x . "," . coord.y . "`n"
}
ToolTip(tagContent)
}
trivial question, as v2 is already a breaking change, why don't just make all built-in function works similar like return value = func(arguments). There're still two types of function styles which is a little bit confusing
I mean functions like MouseGetPos should be works like {x:0,y:0,win:blahobj, control:blahobj} = MouseGetPos(flag)