Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm trying to figure Tables and Dictionaries?

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

5 comments

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

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

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()

0

Aw okay :( I'll do that Thanks

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

1 answer

✓ Accepted answer

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.

1 comment

0

Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.