Page 1 of 1

[SOLVED] Calling function with SetTimer

Posted: 04 May 2015, 13:57
by vasili111
How to make this work?

Code: Select all

a := 12
SetTimer, z(a), -0

z(a)
{
	MsgBox, % a
}

Re: Calling function with SetTimer

Posted: 04 May 2015, 15:00
by ameyrick

Code: Select all

a := 12
SetTimer, z, -0
Return

z:
SetTimer, z, off
result := z(a)
Return

z(a)
{
	MsgBox, % a
}

Re: Calling function with SetTimer

Posted: 04 May 2015, 15:11
by tmplinshi

Code: Select all

#Persistent

a := 12
fn := Func("z").Bind(a)
SetTimer, %fn%, -0

z(a)
{
    MsgBox, % a
}

Code: Select all

#Persistent

a := 12
fn := ObjBindMethod(myClass, "z", a, "bbb")
SetTimer, %fn%, -0

class myClass {
	z(a, b) {
		MsgBox, % a "`n" b
	}
}

Re: Calling function with SetTimer

Posted: 04 May 2015, 16:15
by vasili111
Thank you for help :)
Solved.

Re: [SOLVED] Calling function with SetTimer

Posted: 07 May 2015, 14:35
by Guest10
what are the advantages of tmplinshi's over ameyrick's. tmplinshi's looks overly complicated! :morebeard:

Re: [SOLVED] Calling function with SetTimer

Posted: 07 May 2015, 15:15
by vasili111
Guest10 wrote:what are the advantages of tmplinshi's over ameyrick's. tmplinshi's looks overly complicated! :morebeard:
At that time I need to directly call function in SetTimer without label so tmplinshi's examples at that situation are very useful. I need to use SetTimer inside another function.

Re: [SOLVED] Calling function with SetTimer

Posted: 07 May 2015, 17:46
by Guest10
when i run this, it says:
Error: Target label does not exist.
---> SetTimer, %fn%, -0
The current thread will exit.

:morebeard:

Code: Select all

#Persistent
#SingleInstance Force
#NoEnv

a := 12
fn := Func("z").Bind(a)
SetTimer, %fn%, -0

z(a)
{
    MsgBox, % a
}

Re: [SOLVED] Calling function with SetTimer

Posted: 07 May 2015, 19:35
by tmplinshi
Guest10 wrote:when i run this, it says:
Error: Target label does not exist.
---> SetTimer, %fn%, -0
The current thread will exit.

:morebeard:

Code: Select all

#Persistent
#SingleInstance Force
#NoEnv

a := 12
fn := Func("z").Bind(a)
SetTimer, %fn%, -0

z(a)
{
    MsgBox, % a
}
Requires AutoHotkey v1.1.20+.

Re: [SOLVED] Calling function with SetTimer

Posted: 07 May 2015, 19:55
by Guest10
thanks, upgraded AHK from 19 to 22, and now it works!

Re: Calling function with SetTimer

Posted: 25 Aug 2019, 13:27
by pk23
tmplinshi wrote:
04 May 2015, 15:11

Code: Select all

#Persistent

a := 12
fn := Func("z").Bind(a)
SetTimer, %fn%, -0

z(a)
{
    MsgBox, % a
}

Code: Select all

#Persistent

a := 12
fn := ObjBindMethod(myClass, "z", a, "bbb")
SetTimer, %fn%, -0

class myClass {
	z(a, b) {
		MsgBox, % a "`n" b
	}
}
only login for saying thank you! :bravo: