• 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 how to print an item from a row in a table?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
177
Location
Sweden
As topic says, how do you print a itemid & amount from a row in a table in lua?

Say i have:
Lua:
table = {
{
     firstList = {
{{2160, 5}, {2160, 10}, {2160, 2}},
{{2160, 10}, {2160, 3}, {2160, 2}},
},
     secondList = {
{{2160, 3}, {2160, 10}, {2160, 2}},
{{2160, 10}, {2160, 3}, {2160, 5}},
},
}}
What i want example: To print the secondList, second row, and the middle value of (2160, 3), meaning i want both the itemid and the amount.
 
I think this will do the trick
Lua:
firstlist[indexOfRow][IndexOfItemInsideRow][IndexOfItem]

edit**
This is just a small edit of your code
Lua:
table = {
     firstList = {
    {{2160, 5}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 2}},
    },
         secondList = {
    {{2160, 3}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 5}},
    },
}

print(table.firstList[1][1][1]) -- 2160

This is your code
Lua:
table = {
{
     firstList = {
    {{2160, 5}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 2}},
    },
         secondList = {
    {{2160, 3}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 5}},
    },
}}

print(table[1].firstList[1][1][1]) -- 2160

Tested with JDoodle - free Online Compiler, Editor for Java, C/C++, etc (https://www.jdoodle.com/execute-lua-online/)
 
Last edited:
I think this will do the trick
Lua:
firstlist[indexOfRow][IndexOfItemInsideRow][IndexOfItem]

edit**
This is just a small edit of your code
Lua:
table = {
     firstList = {
    {{2160, 5}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 2}},
    },
         secondList = {
    {{2160, 3}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 5}},
    },
}

print(table.firstList[1][1][1]) -- 2160

This is your code
Lua:
table = {
{
     firstList = {
    {{2160, 5}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 2}},
    },
         secondList = {
    {{2160, 3}, {2160, 10}, {2160, 2}},
    {{2160, 10}, {2160, 3}, {2160, 5}},
    },
}}

print(table[1].firstList[1][1][1]) -- 2160

Tested with JDoodle - free Online Compiler, Editor for Java, C/C++, etc (https://www.jdoodle.com/execute-lua-online/)
Thanks and I'd tried to google this and found nothing but gave up too quick I believe, thanks for explaining it good aswell! =D
 
Back
Top