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

index expected, got nil

Started by augustas656, 10 July 2013 - 03:37 PM
augustas656 #1
Posted 10 July 2013 - 05:37 PM
I need help with tables, I want to insert a value into a table that exists within a table.
for example:

a = {}
a[1] = {x = 5, y = 4}
print(a[1][x])
gives me just a blank space.
Is there any way of me inserting like so without using textutils.serialize?
I got an error for a code I was using

a = {}
a[1][x] = 5
and it said "index expected, got nil"
Engineer #2
Posted 10 July 2013 - 05:58 PM

local a = {}
a[1] = {}
a[1]["x"] = 5 -- OR:
a[1].x = 5

It needs to be a table in short
augustas656 #3
Posted 11 July 2013 - 12:22 PM
THANK YOU!!! I could've found this out myself, although I was kinda lazy, but this didn't just help me with the script I had a problem with, now 3 different things that are really complex are extremely more easier to understand for me!!!