So I'm making a point system for ranks ups and such so I made a dictionary to try and make it all organized but I can't figure how out to go forwards and backwards on the list. What I mean is something like this **(RankData[2]) ** so it gets the string/value second from the top, I have this so far.
local CurrentRank = "Premium Customer" local LastRank = nil local RankData = { ["Premium Customer"] = 40, ["VIP Customer"] = 60, ["Noted Customer"] = 100, ["Tainee"] = 130, ["Customer Service"] = 170, ["Attendant"] = 220, ["Senior Attendant"] = 280, ["Host/Hostess"] = 350, ["Supervisor"] = 440, ["Interview Managment"] = 550, ["Board of Directors"] = 680, ["Chairman of the Board"] = 800, ["Chief Operational Officer"] = 1500, ["Chief Executive Officer"] = 2000, ["Vice President"] = 3000, ["President"] = 5000, ["Vice Chairman"] = 7000, } --print(RankData[1]["Premium Customer"]) --local nums = (unpack(RankData)) for i,v in pairs (RankData) do print("Current Rank is " .. CurrentRank) print("Next rank will be " .. RankData['Premium Customer']) LastRank = CurrentRank ---HOW can I go back, or forward like ---(RankData[2]) so it does to the second item on the list which would be "VIP Customer" end
Dictionaries are unordered. That means when you have string keys like this, you can't tell which one is "first" or "last".
If you want an ordered collection of things, that's called a list.
The nicest structure for that would probably look like this:
local RankData = { {name = "Premium Customer", points = 40}, {name = "VIP Customer", points = 60}, {name = "Noted Customer", points = 100}, -- etc }
Then RankData[1]
is the first "rank" which has a RankData[1].name
and a RankData[1].points
.