Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I get the name of a table object?

Asked by 6 years ago

Say I have this script...

1local Passes = {["DjDoor"] = 4846905
2            }

How would I be able to to get the name "DjDoor" if I had the ID 4846905? Would I have to make ["DjDoor"] an array and add another string like this...?

1local Passes = {["DjDoor"] = {4846905, "DjDoor"}
2            }

Or is there another way to obtain it?

1 answer

Log in to vote
2
Answered by 6 years ago

Just use a key-value for loop:

1for key, value in pairs(Passes) do
2    if value == 4846905 then
3        print(key, value) -- You can access both
4    end
5end
1
Thanks, for some reason I thought that would have returned the index number. climethestair 1663 — 6y
0
No worries, we all get those brain dead moments lol ScrewDeath 153 — 6y
Ad

Answer this question