Page 1 of 1

how to I can add array parameter ?

Posted: 21 Jun 2018, 05:31
by gameba
Hi, guys
Pls, help how to I can add array parameter ? I try below code but it isn't work
p/s I use AHK_H v1 64bit

Code: Select all

array:=[1,2,3,4]
threads:=[]
Loop 3
threads[A_Index]:=AhkThread("
(
	var:=A_Args[1]
	msgbox % var[1]
	Return

)", array)

ESC::
ExitApp
if the array are not allow,so How do I assign array from main code into a thread?

Thanks!

Re: how to I can add array parameter ?  Topic is solved

Posted: 21 Jun 2018, 14:30
by HotKeyIt
You can pass the parameters as usual ..., 1 2 3 4, just make sure it is a string!
You can also pass an object reference and use the object itself:

Code: Select all

array:=[1,2,3,4]
threads:=[]
Loop 3
threads[A_Index]:=AhkThread("
(
	var:=Object(A_Args[1])
	msgbox % var[" A_Index "]
	Return

)", (&array) "")

ESC::
ExitApp
If multiple threads need to access the object use CriticalObject instead!

Re: how to I can add array parameter ?

Posted: 21 Jun 2018, 19:45
by gameba
@HotKeyIt awesome. Thank you very much! :D

Re: how to I can add array parameter ?

Posted: 22 Jun 2018, 07:36
by HotKeyIt
Forgot to mention, you can also use named parameters in v2:

Code: Select all

thread:=AhkThread("
(
	msgbox A_Args.name "``n" A_Args.version
	Return

)", "name ahk version 1")

ESC::
ExitApp