[ERROR] SetTimer("LABEL", ...)

Discuss the future of the AutoHotkey language
_3D_
Posts: 134
Joined: 29 Jan 2014, 14:40

[ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 05:11

AutoHotkey 078 Perfect working.

Code: [Select all] [Download] GeSHi © Codebox Plus

ExtensionConvert()
ExtensionConvert() {
LABEL_ExtensionConvert:
tooltip(A_ThisLabel " : " a++) ; action too long >>> so timer off
SetTimer("LABEL_ExtensionConvert", "Off")
FileMove("c:\temp\*.S*24", "c:\temp\*.S$$")
FileMove("c:\temp\*.K*24", "c:\temp\*.K$$")
; run timer again
SetTimer("LABEL_ExtensionConvert", 998)
RETURN ;not needed
}
AutoHotkey_2.0-a081-cad307c

Code: [Select all] [Download] GeSHi © Codebox Plus

ExtensionConvert()
ExtensionConvert() {
LABEL_ExtensionConvert:
tooltip(A_ThisLabel " : " a++) ; action too long >>> so timer off
SetTimer("LABEL_ExtensionConvert", "Off") ; Erro: Target label does not exist.
; Specifically: LABEL_ExtensionConvert
FileMove("c:\temp\*.S*24", "c:\temp\*.S$$")
FileMove("c:\temp\*.K*24", "c:\temp\*.K$$")
SetTimer("LABEL_ExtensionConvert", 998)
RETURN
}
When first call everything OK. When SetTimer call only SetTimer() can`t see Label. A_ThisLabel is set to "invisible" label.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

The same.
There no scope problem with label due to settimer calls runs and A_ThisLabel is set correctly.
AHKv2.0 use the future now.
_3D_
Posts: 134
Joined: 29 Jan 2014, 14:40

[ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 05:48

Code: [Select all] [Download] GeSHi © Codebox Plus

ExtensionConvert() {
LABEL_ExtensionConvert:
label:= A_ThisLabel? "": "LABEL_ExtensionConvert" ; second call with "unckown" label ("")
tooltip(A_ThisLabel " | " label " : " a++) ; visual debug line
SetTimer(label, "Off")
FileMove("c:\temp\*.S*24", "c:\temp\*.S$$")
FileMove("c:\temp\*.K*24", "c:\temp\*.K$$")
SetTimer(label, 998)
RETURN
}
Working but ugly.
If A_ThisLabel is set SetTimer must use "" as label.

Edit after test:

Code: [Select all] [Download] GeSHi © Codebox Plus

ExtensionConvert() {
label:= "LABEL_ExtensionConvert" ; set label for first
LABEL_ExtensionConvert:
SetTimer(label, "Off") ; when SetTimer call label is ""
FileMove("c:\temp\*.S*24", "c:\temp\*.S$$")
FileMove("c:\temp\*.K*24", "c:\temp\*.K$$")
SetTimer(label, 998)
RETURN
}
AHKv2.0 use the future now.
SirRFI
Posts: 228
Joined: 25 Nov 2015, 16:52

Re: [ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 06:40

How about this?:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Uses function or method instead of label.
Use [code=autohotkey] forum tag to share your code.
Click on (Accept this answer) on top-right part of the post if it has answered your question / solved your problem.
_3D_
Posts: 134
Joined: 29 Jan 2014, 14:40

Re: [ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 08:10

Idea is to separate function body to call action and timer call action.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

https://autohotkey.com/boards/viewtopic.php?f=19&t=1773&p=10488#p10488
This way function encapsulate timer itself and timer execute just part of function code.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Just for fun.
Last edited by _3D_ on 02 Sep 2017, 08:54, edited 1 time in total.
AHKv2.0 use the future now.
HotKeyIt
Posts: 1501
Joined: 29 Sep 2013, 18:35
Contact:

Re: [ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 08:25

For convenience this could be fixed by adding this code here.

Code: [Select all] [Download] GeSHi © Codebox Plus

	if (g->CurrentLabel && !_tcsicmp(g->CurrentLabel->mName, aLabelName))
return g->CurrentLabel;


EDIT:
I have created a pull request.
lexikos
Posts: 5410
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [ERROR] SetTimer("LABEL", ...)

02 Sep 2017, 17:29

The function is not called, so no (other) local variables or labels are accessible dynamically. HotKeyIt's "fix" adds an inconsistency to the language, making A_ThisLabel accessible but not any other local labels or variables. My preference is to leave it as is.

If you want encapsulation, you can use an object or bound function.
_3D_
Posts: 134
Joined: 29 Jan 2014, 14:40

Re: [ERROR] SetTimer("LABEL", ...)

03 Sep 2017, 06:55

lexikos wrote:The function is not called, so no (other) local variables or labels are accessible dynamically. HotKeyIt's "fix" adds an inconsistency to the language, making A_ThisLabel accessible but not any other local labels or variables. My preference is to leave it as is.

If you want encapsulation, you can use an object or bound function.
Correct. Code enclosed in LABEL/RETURN that timer call is local for itself when timer call. And it CAN`T see other local variables and labels and CAN`T manipulate it. Problem is: at the next line after LABEL A_ThisLabel is not set (mean == "").

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Gosub init LB_2 and in case (2) Goto init LB_1 so settimer can be used SetTimer(, value). In case (1) no Goto and must use SetTimer(A_ThisLabel? "": "LB_1") that is the same to using local variable (that is "" when timer call and "LB_1" in function call).

Code: [Select all] [Download] GeSHi © Codebox Plus

nul() {
LABEL:
msgBox(A_ThisLabel) ; ""
}

Code: [Select all] [Download] GeSHi © Codebox Plus

nul() {
Goto("LABEL")
LABEL:
msgBox(A_ThisLabel) ; "LABEL"
}
Timer work perfect but A_ThisLabel must be set forced.
Edited:
BTW

Code: [Select all] [Download] GeSHi © Codebox Plus

LABEL 				  ; missing :
msgBox("No Run.") ; <<< dead code
return
Script can`t run and no any Error.

Code: [Select all] [Download] GeSHi © Codebox Plus

123.2 ;No object to invoke. ??? var begin [a-z_]
AHKv2.0 use the future now.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 1 guest