• 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!

TFS 1.X+ get table size?! for put , and . in message

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
How can i get this table size?
I need to put "," after names, but in last i need to put "."
Need print(text) -> text = You need to kill: rat, rotworm, dragon.

LUA:
local configs = {
["rat"] = {
{5, 100},
},

["rotworm"] = {
{5, 150},
},

["dragon"] = {
{75, 150},
},
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        text = "You need to kill:"
  
        for name, tabela in pairs(configs) do
            text = ""..text.." ".. name ..","
            -- how i can get the size of table config?
            --if i use print (#config) it print 0
            --how can i put "." after last name?
        end
            --print(text)
    return true
end
 
Last edited:
Solution
You can use this function
LUA:
function table.length(t)
    local len = 0
    for _ in pairs(t) do
        len = len + 1
    end
    return len
end

if i use print (#config) it print 0

Operator # wasnt working because doesnt work with tables that arent arrays

For example, if u have a table like this:
LUA:
local t = {1, 2, ["rat"] = {5, 100}, 4}

And you use #configs, it will print 3 because only 1, 2 and 4 are part of the array.
You can use this function
LUA:
function table.length(t)
    local len = 0
    for _ in pairs(t) do
        len = len + 1
    end
    return len
end

if i use print (#config) it print 0

Operator # wasnt working because doesnt work with tables that arent arrays

For example, if u have a table like this:
LUA:
local t = {1, 2, ["rat"] = {5, 100}, 4}

And you use #configs, it will print 3 because only 1, 2 and 4 are part of the array.
 
Solution
Back
Top