Jump to content




Tables In Tables


  • You cannot reply to this topic
2 replies to this topic

#1 blipman17

  • Members
  • 92 posts

Posted 03 October 2013 - 04:47 PM

i'm, trying to acces a table in a table, but i can't get it right.
i have the following piece of code just to try it.
stonestairs={}
craftables={stonestairs}
textutils.tabulate{craftables}
i want to be able to store a yet unknown amounth of tables in craftables, but i do want to access the value's of certain keys in those tables. I just can't get it working, could anyone help me? that would be wonderfull.

my excuses for my English level, I'm Dutch.

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 03 October 2013 - 05:27 PM

You're using the function textutils.tabulate without parentheses, which are required. It should be
textutils.tabulate(craftables)

As your code is given though, this will not output anything due to the fact that both tables are empty.


Also, though assigning a table to a variable and then inserting it into another table is valid, you can use several other methods that may make your life simpler.
1) table.insert(table, item)
Example:
local craftables = {}
table.insert(craftables, {"This", "Has","Stuff"})

2) table[index] = value
Example:
local craftables = {}
craftables[1] = {"Table", "Within", "A", "Table"}

3) Use the "dot" operator
Example
local craftables = {}
craftables.someTable = {"This","is","for","named","tables"}

4) Directly insert into the table
Example
local craftables = {
  [1] = {"Hello!"};
  [2] = {"Stuff", "Table"};
}


#3 AgentE382

  • Members
  • 119 posts

Posted 03 October 2013 - 10:50 PM

Uh, Bubba... You can call Lua functions with a single table argument, omitting the parentheses. This:
textutils.tabulate{craftables}
is equivalent to this:
textutils.tabulate({craftables})
It constructs a new table with a reference to craftables stored as index 1.

All of his calls condense to this:
textutils.tabulate({[1] = {[1] = {}}})

I think any of your options would definitely make his code simpler.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users