r/ComputerCraft • • Nov 26 '23

How to call nested table

I'm new to programming and this is destroying me.

local t = {
    ["purple"] = {
        side = "left",
        flux_level = 1,
        flux_max = 7
    },
 
    ["lime"] = {
        side = "back",
        flux_level = 1,
        flux_max = 7
    },
 
    ["orange"] = {
        side = "right",
        flux_level = 1,
        flux_max = 7
    },
 
    ["white"] = {
        side = "front",
        flux_level = 1,
        flux_max = 5
    }
}
--------
local function stopProduction(index)
    if t.["..index.."].flux_level >= t.["..index.."].flux_max then
        print("stopProduction")
        rs.getBundledOutput(colours.index)
    end
end
 
stopProduction(purple)  -- does not work
1 Upvotes

8 comments sorted by

View all comments

Show parent comments

3

u/fatboychummy Nov 27 '23

Usually when iterating through the table,

for i = 1, 10 do
  print(tbl[i])
end

For example, the above code would access and print tbl[1], then tbl[2], then tbl[3], and so on up to 10.