Array indexing in Commands Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Frozen Storm
Posts: 15
Joined: 24 Aug 2016, 09:43

Array indexing in Commands

17 Feb 2018, 10:58

I have the following code:

Code: Select all

MouseGetPos, x, y
a := [SomeFunction(x), SomeFunction(y)]
IniWrite, a[1]`,a[2], asdf.ini, Other, A
The expected result in the .ini file is something like

Code: Select all

[Other]
A=5,3
where 5 and 3 are the respective results of the SomeFunction calls. But instead I get

Code: Select all

[Other]
A=a[1],a[2]
How do I properly address an array element in a Command call? I tried surrounding them with %, but that raised an error.
User avatar
boiler
Posts: 16954
Joined: 21 Dec 2014, 02:44

Re: Array indexing in Commands  Topic is solved

17 Feb 2018, 11:07

You need to force it into expression syntax, then you need to write it in expression syntax, like this:

Code: Select all

IniWrite, % a[1] "," a[2], asdf.ini, Other, A
Frozen Storm
Posts: 15
Joined: 24 Aug 2016, 09:43

Re: Array indexing in Commands

19 Feb 2018, 16:43

Thanks! Is there also a way to use arrays as Output variables (which don't allow forced expression syntax, according to the docs)? The below code raises an error:

Code: Select all

mousePos := []
MouseGetPos, mousePos[1], mousePos[2]
User avatar
boiler
Posts: 16954
Joined: 21 Dec 2014, 02:44

Re: Array indexing in Commands

19 Feb 2018, 16:46

In that case, you have to use regular variables, then assign them to your array elements afterwards.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, rc76, uchihito and 366 guests