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

Solved print a number of a table

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
177
Location
Sweden
How would you procceed in order to print one of the desired numbers in the '['-brackets without using the number inside?

Lua:
local charmStats = {
    [13508] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [24322] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [5810] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [32914] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+2%", "+3%"}},
}

In a table like this:
local charmStats = {3,4,5,2,1,4,6,8,2,5,8,9,12,5,2}
you can simply print(charmStats[3]), I want same functioning but in the upper table.
Post automatically merged:

How would you procceed in order to print one of the desired numbers in the '['-brackets without using the number inside?

Lua:
local charmStats = {
    [13508] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [24322] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [5810] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [32914] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+2%", "+3%"}},
}

In a table like this:
local charmStats = {3,4,5,2,1,4,6,8,2,5,8,9,12,5,2}
you can simply print(charmStats[3]), I want same functioning but in the upper table.
Solved with this lil line:

Lua:
for _ in pairs(charmStats) do
    print(_)
end
 
Last edited:
Lua:
local charmStats = {
    [1] = {key = 13508, sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [2] = {key = 24322, sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [3] = {key = 5810, sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}},
    [4] = {key = 32914, sockets = 2, statType = {"HP", "MP"}, statAmount = {"+2%", "+3%"}},
}

charmStats[1].key

If you need to keep the table as associative, then you could so something like:
Lua:
local charmStats = {
    [13508] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}, index = 1},
    [24322] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}, index = 2},
    [5810] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+250", "+350"}, index = 3},
    [32914] = {sockets = 2, statType = {"HP", "MP"}, statAmount = {"+2%", "+3%"}, index = 4},
}

local index = {}
for k, v in pairs(charmStats) do
     index[v.index] = k
end

print(charmStats[index[1]])
 
Last edited:
Back
Top