I'm currently creating a skill tree but when I try to find a variable inside of the dictionary and print it, it prints out "nil" and not what's inside of Character
local Skills = { Character = { PointsRequired = 0, }; Skill1 = { PointsRequired = 1, }; } Skills.putPoint = function(plr,Target,TargetName) local node = table.find(Skills,"Character") print(node) end return Skills
any idea why?
Index keys like this
local node = Skills["Character"] -- or local node = Skills.Character print(node)
It won't error but will return nil if the key is not in the table.
In your case are using table.find
wrong, this function searches for value instead of key and returns position of the value inside of the table, it only works on values without keys, like this:
local Array = { "Cat", "Another Cat", "Another Another Cat", "Another Another Another Cat", "Giraffe", ["oh"] = "no", } table.find(Array, "Cat") -- 1 table.find(Array, "Another Another Cat") -- 3 table.find(Array, "Gorilla") -- nil table.find(Array, "oh") -- nil table.find(Array, "no") -- nil
I also recommend you declaring functions like this instead as it's preferred syntax for that
function Skills.putPoint(plr, Target, TargetName) [...] end