• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Using a loop in a table, but getting nil value

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,796
Solutions
581
Reaction score
5,359
Alright.. so basically a quick question.

How do I do the thing I'm trying to do? xD

I want to use lists to print 1,3,5,7

But no matter what I try, it can't find what I'm looking for..
presumably because lists[n] is making it look somewhere else.

I'm just stuck.. xD
Lua:
local config = {
    [1111] = {
        [1] = {
            [1] = {
                list1 = {{1, 11}, {2, 22}},
                list2 = {{3, 33}, {4, 44}},
                list3 = {{5, 55}, {6, 66}},
                list4 = {{7, 77}, {8, 88}}
            },
            [2] = {},
            [3] = {},
            [4] = {}
        }
    },
}

local lists = {list1, list2, list3, list4}

for n = 1, 4 do
    print(config[1111][1][1].lists[n][1])
end
 
Don't you have to index the table in your table of tables?
Lua:
lists = { config[1111].[1].[1].list1 }
or something like that.
 
Don't you have to index the table in your table of tables?
Lua:
lists = { config[1111].[1].[1].list1 }
or something like that.
I ended up with this solution.. xD

I put it into quotation marks surrounded by []
Lua:
local config = {
    [1111] = {
        [1] = {
            [1] = {
                ["list1"] = {{1, 11}, {2, 22}},
                ["list2"] = {{3, 33}, {4, 44}},
                ["list3"] = {{5, 55}, {6, 66}},
                ["list4"] = {{7, 77}, {8, 88}}
            },
            [2] = {},
            [3] = {},
            [4] = {}
        }
    },
}

local lists = {"list1", "list2", "list3", "list4"}

for n = 1, 4 do
    print(config[1111][1][1][lists[n]][1][1])
end
 
Back
Top