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

I'm trying to figure Tables and Dictionaries?

Asked by 8 years ago

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
0
i may be wrong but you can't use numbers when the table uses strings. try (RankData["Premium Customer"]) that should give you 40 lukeb50 631 — 8y
0
I know how to do that, I just wanted to know if I could do the (RankData[2]) so I can transition from one rank to the other without knowing the name so that it becomes easy to add onto/edit xXharvest109Xx 25 — 8y
0
no you cant do that. what you would need to do is use a folder and have stringvalues in them with the ranks as the value and the number as the name and use :FindFirstChild() lukeb50 631 — 8y
0
Aw okay :( I'll do that Thanks xXharvest109Xx 25 — 8y
0
np. just a hint you will need to put a letter before the number. you can do that by separating the 2 like this: .Name="A" .. Variable lukeb50 631 — 8y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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.

0
Thank you so much! xXharvest109Xx 25 — 8y
Ad

Answer this question