Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Quick: How Do I Make a Multidimensional Array?



  • Please log in to reply
2 replies to this topic
Chunjee
  • Members
  • 57 posts
  • Last active: Jan 13 2015 09:18 PM
  • Joined: 30 Nov 2012

I can't figure out how to create a multidimensional array, The documentation here shows how to use them well and fine:

table[x][y] := content  ; A
table[x, y] := content  ; B

but I can't figure out how to create them to start with. I know how to make a simple array. Like in this function I have:

SimpleEmptyArray := []
RandomNoRepeats(Total)
{
global
IncrementArray := []
RandomizedArray := []
X = 0
	Loop, %Total% ; Create an array of sorted numbers 1-Total
	{
	X += 1
	IncrementArray.Insert(x)
	}
	
X = 0
	Loop, %Total% ; Take random element from IncrementalArray and put it into RandomizedArray
	{
	X += 1
	CurrentSize := IncrementArray.MaxIndex() ;gets current size of 1-Total array. This will eventually be 0 when it is empty
	Random, Rand, 1, %CurrentSize%
	
	Alf := IncrementArray[Rand]
	IncrementArray.Remove(Rand,Rand)
	RandomizedArray.Insert(Alf)
	
		if (CurrentSize = "")
		{
		Msgbox, Done creating
		}
		
	}

}

I did my best to google the answer this morning and more than I'd care to admit yesterday. I know this is going to be something simple like two separate arrays inside each other so be gentle. 



HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
✓  Best Answer
Arr := [[1],[2],[3]]
MsgBox % Arr.1.1 "`n" Arr.2.1 "`n" Arr.3.1

If you want named arrays:

Arr := {a1:[1],a2:[2],a3:[3]}
MsgBox % Arr.a1.1 "`n" Arr.a2.1 "`n" Arr.a3.1


Chunjee
  • Members
  • 57 posts
  • Last active: Jan 13 2015 09:18 PM
  • Joined: 30 Nov 2012

You cool. I need to setup IRC again because I just realized this would have been much easier to accomplish in the chatroom.