
Currently if i said print(Rarities[2]) it would print 30 but how do i get it to print Powerful instead?
Rarities[2] wouldn’t be possible in a non-dictionary.
Use actual value.
local _rarities = {
Powerful = 60,
Rocky = 40
}
local function _trouverKey(_valeur: any?, _table : {})
if not _valeur then
return nil
end
for t,v in _table do
if v == _valeur then
return t
end
end
end
print(_trouverKey(60, _rarities))
1 Like
i would convert it to a dictionary
local Rarities = {
['Basic'] = 57.5,
['Powerful'] = 30,
['Divine'] = 10,
['Atomic'] = 2,
['Celestial'] = 0.5,
}
then referring to it would be
Rarities.Powerful to return 30
and then to loop through the table you can do
for i,v in pairs(Rarities) do
print(i) -- will print basic, powerful, divine etc.
print(v) -- will print the values of the index/key above
end
i think this would be what you’re looking for
2 Likes
They were already using a dictionary.
1 Like
local function getKeyByIndex(t, i)
local newT = {}
for k in t do
table.insert(newT, k)
end
return newT[i]
end
1 Like