This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
htothe2oh's profile picture

Array Within Array Error: "}" Expected

Started by htothe2oh, 15 October 2012 - 11:39 PM
htothe2oh #1
Posted 16 October 2012 - 01:39 AM
I've been reading around a lot and experimenting with different things, but none of them seem to work. Basically what I am trying to do is:


local stuff = {"subArray" = {"A" = 7, "B" = 8, "torch" = 9}, "subArray 2" = {"A" = 1, "B" = 2, "torch" = 3}}

and that SHOULD be working, but I get an error saying "}" expected on that line. Before when I was working with concatenating strings, I would get this error when I forgot the "..", so I assumed I missed a comma or something. After careful inspection I found that I had done everything as I thought I should!

I tried reformatting it to do the same thing, but in a different way, and came up with this:

local stuff = {}
stuff["subArray"] =  {"A" = 7, "B" = 8, "torch" = 9}
stuff["subArray2"] = {"A" = 1, "B" = 2, "torch" = 3}

and this



local stuff = {}
stuff.subArray =  {"A" = 7, "B" = 8, "torch" = 9}
stuff.subArray2 = {"A" = 1, "B" = 2, "torch" = 3}

Again it gave me the same error

am I missing something?
Luanub #2
Posted 16 October 2012 - 01:43 AM
Try it like this:

local stuff = {[subArray] = {"A" = 7, "B" = 8, "torch" = 9}, [subArray 2] = {"A" = 1, "B" = 2, "torch" = 3}}
Kingdaro #3
Posted 16 October 2012 - 01:46 AM
You need square brackets around your string indexes.

local stuff = {
 ["subArray"] = {
  ["A"] = 7,
  ["B"] = 8,
  ["torch"]= 9
 },
 ["subArray 2"] = {
  ["A"] = 1,
  ["B"] = 2,
  ["torch"] = 3
 }
}
robhol #4
Posted 16 October 2012 - 06:28 AM
Either [] or just { foo=2, bar=42 } will do.