Heya every1!
I’m in a hurry right now, so this post isn’t good.
But how do i go to the next value in a table.
like this table
local Colors = {
[“Patience”] = BrickColor.new(“Toothpaste”),
[“Determination”] = BrickColor.new(“Really red”),
[“Kindness”] = BrickColor.new(“Lime green”),
[“Bravery”] = BrickColor.new(“Br. yellowish orange”),
[“Intergity”] = BrickColor.new(“Dark blue”),
[“Justice”] = BrickColor.new(“Brick yellow”),
[“Perseverance”] = BrickColor.new(“Royal purple”)
}
if i want to go from patience to the next value, is there any specific function like Table:Next() or something?
Thanks
If you are on Patience and what the next entry, you can use this.
next(Colors, “Patience”)
Dictionaries (In Vanilla Lua at least) don’t have a specified order though, so it may not give you exactly what you want. If that is the case, you will need to re-work it so that it uses numbers instead of strings for the keys.
That is exactly what that is. I believe he is suggesting that you can integrate it with whatever you’re doing. Or maybe he misunderstood. Without knowing why you need it, it can be difficult to recommend the best method.
next takes a key, not a value. Colors[“Determination”] is a value, “Determination” is the key to access it.
game:GetService("UserInputService").InputBegan:Connect(function(input, gp)
if gp then return end
if input.KeyCode == Enum.KeyCode.E then
table.find(Colors,"Determination")
print(Colors["Determination"])
currentTrait = "Determination"
nextTrait, value = next(Colors,currentTrait)
-- so now nextTrait="Kindness", value=BrickColor.new("Lime green")
currentTrait = nextTrait
end
end)