Thank you and have a nice day
Code: Select all
#Requires AutoHotkey v2
#Singleinstance
Persistent
Tictoc := 5000
SetTimer MyTimer(Tictoc), 1000
MyTimer(x){
ToolTip x
x++
}
Code: Select all
#Requires AutoHotkey v2
#Singleinstance
Persistent
Tictoc := 5000
SetTimer MyTimer(Tictoc), 1000
MyTimer(x){
ToolTip x
x++
}
Code: Select all
#Requires AutoHotkey v2
#Singleinstance
Persistent
Tictoc := 5000
SetTimer MyTimer, 1000
MyTimer(){
Global Tictoc
ToolTip Tictoc
Tictoc++
}
Code: Select all
SetTimer MyTimer.Bind("hello", "world"), 1000
MyTimer(A, B){
MsgBox A "`n" B
ExitApp
}
Code: Select all
obj := {Tictoc: 1000, Tictoc2:2000}
obj.Function := MyTimer.Bind('Tictoc')
SetTimer(obj.Function, 1000)
^1:: {
SetTimer(obj.Function, 0)
obj.Function := MyTimer.Bind('Tictoc2')
SetTimer(obj.Function, 1000)
}
^2::SetTimer(obj.Function, 0)
MyTimer(param) {
obj.%param%++
Tooltip obj.%param%
}
That has been somewhat of an annoyance for me as well in moving to V2. I don't know why the decision was made to allow statement-style syntax for functions rather than purely function-style (with parens). Plus, it only works with select functions - Send, MsgBox, etc. For others, you must use parens. I personally stick with function-style for consistency as I was completely confused for a long time by the different syntax options within V1.google wrote: I notice that SetTimer can be written in 2 different ways. I thought AHK2 was written to remove the ambiguity.
Code: Select all
obj := []
obj.push "A"
Code: Select all
if (3 != 4)
FAIL
FAIL() {
MsgBox "Function failed"
}
RussF wrote: ↑09 Oct 2023, 09:45I don't think you can pass an argument, however, since you are setting a variable just before your call to SetTimer anyway, you can:
RussCode: Select all
#Requires AutoHotkey v2 #Singleinstance Persistent Tictoc := 5000 SetTimer MyTimer, 1000 MyTimer(){ Global Tictoc ToolTip Tictoc Tictoc++ }
Declaring a variable as global outside of a function no longer creates a "super-global" variable since they no longer exist in v2, as this part about Scope in Changes from v1.1 to v2.0 describes. It is described in the main part of the documentation in Global Variables.j46 wrote: ↑ In the example below, you declare the Tictoc variable as global INSIDE the timer.
...
This was new to me and not the way I did it in V1 (right or not, I guess). I assigned variables as Global first thing when declaring them, and the timer (or other) would read them fine.
What is this all about ? Im a bit confused
Code: Select all
#Requires AutoHotkey v2
#Singleinstance
Persistent
MyGlobals := {Tictoc: 5000, OtherVar: 7000}
SetTimer MyTimer, 1000
MyTimer(){
ToolTip MyGlobals.Tictoc
MyGlobals.Tictoc++
}
Code: Select all
MyGlobals := {Tictoc: 5000, OtherVar: 7000}
Stepping := {MyVal: 100}
SetTimer MyTimer, 1000
MyTimer(){
OutputDebug MyGlobals.Tictoc
MyGlobals.Tictoc += Stepping.MyVal ; 5000, 5100, 5200..
}
Code: Select all
MyGlobals := {Tictoc: 5000, Stepping: 100, OtherVar: 7000}
Code: Select all
MyGlobals := {}
MyGlobals.Tictoc := 5000,
MyGlobals.Stepping := 100,
MyGlobals.OtherVar := 7000