hello im trying to get the name of a value in a dictonary.
local things = {
["1"] = "RandomThing",
["2"] = "Rwetpw",
["3"] = "rwerwe",
["4"] = "ewfef"
}
for i,v in pairs(things) do
-- get name of dictonary value (1-4)
-- I dont know how to get name so for example ill use v.Name
if tonumber(v.Name) > 2 then -- THIS DOESN'T WORK... HOW WOULD I DO THIS?
print("success")
end
end
The “v” value is now your string, and the “i” value is default. There’s another fix, and that’s your “v.Name.” Just put “i,” since it’s a table and not unless there’s a table inside of “i” with an object called “Name,” then this will obviously error.
I do recommend you to not put the index values in the tables like that, since they’re default, and it’ll just be a few clicks do fix it anyway.
local things = {
{"1","RandomThing"},
{"2","Rwetpw"},
{"3","rwerwe"},
{"4","ewfef"}
}
for i,v in pairs(things) do
if tonumber(v[1]) > 2 then
print("success")
end
end
local things = {
["1"] = "RandomThing",
["2"] = "Rwetpw",
["3"] = "rwerwe",
["4"] = "ewfef"
}
for key, value in pairs(things) do
if tonumber(key) > 2 then
print("success", key)
end
end
It is tedious, because its not a simple array you can just table.find() . It’s a dictionary and that’s the most simple function that gets values from non numerical indexes.