Multidimensional array

Get help with using AutoHotkey and its commands and hotkeys
euras
Posts: 348
Joined: 05 Nov 2015, 12:56

Multidimensional array

01 Sep 2018, 07:42

is it possible go one or more level deeper then in example I put bellow? Right now I'm able to create arrays like a[1][1] := "stuff". But is it possible to create an array like a[1][1][1] := "stuff" ? if yes, then how can I do it? The task can be i.e. loop through elements, find the right element, set it as array, put elements details in second dimension array, but some of the element details have their own details I want to add to array too. So I need a 3rd level of array. But I cannot figure it out how to do it..

Code: Select all

a := Object()
a[1] := Object()
a[1][1] := "Sub-Array 1, Cell 1"
a[1][2] := "Sub-Array 1, Cell 2"
a[2] := Object()
a[2][1] := "Sub-Array 2, Cell 1"
a[2][2] := "Sub-Array 2, Cell 2"
msgbox, % st_printarr(a)
return

;String Things by tidbit
;https://autohotkey.com/boards/viewtopic.php?f=6&t=53&sid=5c401643235e7a2e73d769f1e5deac0f
st_printArr(array, depth=5, indentLevel="")
{
   for k,v in Array
   {
      list.= indentLevel "[" k "]"
      if (IsObject(v) && depth>1)
         list.="`n" st_printArr(v, depth-1, indentLevel . "    ")
      Else
         list.=" => " v
      list.="`n"
   }
   return rtrim(list)
}
swagfag
Posts: 1563
Joined: 11 Jan 2017, 17:59

Re: Multidimensional array

01 Sep 2018, 09:04

Code: Select all

a := Object()
a[1] := Object()
a[1][1] := Object()
a[1][1][1] := "one"
a[1][1][2] := "two"
User avatar
nnnik
Posts: 3535
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Multidimensional array

01 Sep 2018, 10:04

or even better:

Code: Select all

a :=[]
a[1,1,1] := "One"
a[1,1,2] := "Two"
Recommends AHK Studio
euras
Posts: 348
Joined: 05 Nov 2015, 12:56

Re: Multidimensional array

02 Sep 2018, 07:32

nnnik wrote:or even better:

Code: Select all

a :=[]
a[1,1,1] := "One"
a[1,1,2] := "Two"
But what if I want to put information like this? is it even possible?

Code: Select all

a := []
a[1] := "First level First Item"
a[1,1] := "Second level First Item"
a[1,1,1] := "Third level First Item"
a[2] := "First level Second Item"
a[2,1] := "Second level Second Item"
a[2,1,1] := "Third level Second Item"
msgbox, % st_printarr(a)
return
st_printArr(array, depth=5, indentLevel="")
{
   for k,v in Array
   {
      list.= indentLevel "[" k "]"
      if (IsObject(v) && depth>1)
         list.="`n" st_printArr(v, depth-1, indentLevel . "    ")
      Else
         list.=" => " v
      list.="`n"
   }
   return rtrim(list)
}

Return to “Ask For Help”

Who is online

Users browsing this forum: AnotherUser, Rohwedder and 30 guests