initializing multi dimentional arrays Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
awcrt9316
Posts: 61
Joined: 03 Mar 2020, 20:06

initializing multi dimentional arrays

25 Apr 2020, 11:54

I know how to initialize them like

Code: Select all

 2darray := [[]]  
but that only allows me to add 1 element inside the array. When starting my script, I do not know if I will need to initialize it like this [[], [], []] to have three elements contained in the array, or if i will need 5 elements contained in the array until later on. How would I go about correctly initializing the 2d array? For example,

Code: Select all

if (numberOfArraysIWillNeed = 5)
      array := [[], [], [], [], []]
except the number of arrays I would need could be anywhere from 1 to 500.

someone replied to me with this before
2darray := []


2darray[x, y] := z

but I have no idea how to use that or what it means


this was my attempt to figure this out

Code: Select all



#Persistent
#singleInstance, force


beginning := "[[]"

end := "]"

numofarraysinarray := 5

middle := ",[]"

msgbox, % beginning mushtogether(middle, numofarraysinarray) end


mushtogether(mid, num)
{

	
	loop, % num - 2
	{
	mid := mid ",[]"
	}
return mid
}


return

esc::
exitApp

User avatar
boiler
Posts: 6602
Joined: 21 Dec 2014, 02:44

Re: initializing multi dimentional arrays  Topic is solved

25 Apr 2020, 12:05

Perhaps seeing actual values assigned to the approach that was suggested to you will help you visualize and understand it:

Code: Select all

2darray := []
2darray[1, 1] := "upper-left"
2darray[1, 2] := "upper-right"
2darray[2, 1] := "lower-left"
2darray[1, 2] := "lower-right"

x := 2
y := 1
MsgBox, % 2darray[x, y]
awcrt9316
Posts: 61
Joined: 03 Mar 2020, 20:06

Re: initializing multi dimentional arrays

25 Apr 2020, 12:13

that makes sense now, thanks!

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, effel, JAutohotkey, mikeyww, teadrinker and 48 guests