Doing ObjBindMethod we are assigning the method/function timeMethod to the property/variable runTimer
Doing with global also works (but the we are going global again)
Code: Select all
global runTimer := ObjBindMethod(this, "timerMethod")
SetTimer runTimer, 1
...
SetTimer runTimer, 0
About globals, I usualy do my first trip with new code using globals, and afterwards I try to remove mostly of the globals.
When your code becomes bigger and bigger there's more chance of reusing the same name of an existing global in another part (and then a new bug someday in some situation can happen)
Before ahk I've made my own big spagetti on my own excel vba and this was one of the reasons for some erratic behavior (error was happening just because at random times)
About not using ObjBindMethod I don't know the "real" reason, I've got the working code from the forum after trying the same as you. And here is my own guess (probably is just remotely close to the truth).
The reason SetTimer is not working with this.timerMethod() directly is because SetTimer expects one object (the function) and is receiving both a class and method, and it fails because of the sintax class.method looks like is not the same as one object (dont know why).
Someday I'll have a better answer, but for now this is all I got =P
Btw, I've run your last code and looks like declaring isOn inside of the function carries over to T() without being a global.
Better than my solution and new knowledge aquired (thanks)