Pass values to a SetTimer function? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
j46
Posts: 20
Joined: 23 Apr 2022, 10:29

Re: Pass values to a SetTimer function?

30 Dec 2023, 18:09

just me wrote:
29 Dec 2023, 03:36

as @boiler already said, AHK v2 does not support "super-global variables" any more. But you can achieve a comparable effect if you replace them with properties of an object define in the global scope:
@just me, I ran into this issue today while trying to use objects, are there any trix here or is this a limitation with objects ?

Code: Select all

PIDs := {vlc:"0"} 
run 'vlc.ahk', "D:\Albin\Code\Autohotkey\Autohotkey scripts\Scripts_v2\",,&PIDs.vlc
i get the error ==> "&" requires a variable
just me
Posts: 9542
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Pass values to a SetTimer function?

31 Dec 2023, 05:23

@j46,
it's a limitation. You need to use a variable as temporary target in such case.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: Pass values to a SetTimer function?

31 Dec 2023, 15:03

j46 wrote:
30 Dec 2023, 18:09
just me wrote:
29 Dec 2023, 03:36

as @boiler already said, AHK v2 does not support "super-global variables" any more. But you can achieve a comparable effect if you replace them with properties of an object define in the global scope:
@just me, I ran into this issue today while trying to use objects, are there any trix here or is this a limitation with objects ?

Code: Select all

PIDs := {vlc:"0"} 
run 'vlc.ahk', "D:\Albin\Code\Autohotkey\Autohotkey scripts\Scripts_v2\",,&PIDs.vlc
i get the error ==> "&" requires a variable
I think you could do that with no issues if the property held a variable reference (VarRef) and then dereferenced it outside after giving it to run, but it looks kinda murky and verbose creating var refs on the spot like that. Going by some post I stumbled years ago from lexikos, the reference count on the VarRef would be decreased properly once the original var goes out of scope from the fat arrow, I haven't checked to see if there are other implications.

Code: Select all

PIDs := { vlc: ((ref?)=>&ref)() }

run 'vlc.ahk', "D:\Albin\Code\Autohotkey\Autohotkey scripts\Scripts_v2\",, PIDs.vlc ; no "&" here

msgbox(%pids.vlc%)

pids.vlc := %pids.vlc% ; should release the last reference and leave the var ref to be collected.
User avatar
j46
Posts: 20
Joined: 23 Apr 2022, 10:29

Re: Pass values to a SetTimer function?

04 Jan 2024, 17:53

thx coffee, I have to look into VarRefs :)

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot], niCode, TAC109 and 53 guests