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

Creating a Dictionary/Library?

Hi guys!

I'm trying to create some form of dictionary/library to store lots of values in, so I scripted this:

	local mytable = {
	{ Name= "producttwo", Price = 54234, Colour = Green};
	{ Name = "productone", Price = 123, Colour = Blue};
	{ Name = "productthree", Price = 768, Colour = Red}
	}

The only problem I have, is how to make it usuable like this!! Is there anyway to either print each specific value or filter through and find one with a certain name?

Such as:


for i,v in pairs(1, #table) do
if Name == "producttwo"
print **THAT MINI TABLE IN THE BIG TABLE**
end
end

I know thats not right but is something similar to that, possible?

I've never done anything like this before so any help would be really appreciated! Thanks :D

1 answer

✓ Accepted answer

You have to name the tables

Now, I'm not the best scripter in the world, but I think I understand the problem. You should name the tables inside the table so they can be called more easily. Example,

local mytable = {
	productone = {Price = 54234, Colour = "Green"};
	producttwo = { Price = 123, Colour = "Blue"};
	productthree = {Price = 768, Colour = "Red"}
}

Now let's say we want the price of productone. We need to first use mytable, and then give it productone, and finally tell it to get the Price. Example,

print(mytable.productone.Price)
-- or
print(mytable["producttwo"]["Price"])

-- OUTPUT --
54234
123

We can of course do the same for Color.

print(mytable.productthree.Colour)

-- OUTPUT --
Red

Let me know if you need something explained further, or if I didn't answer your question correctly.

Good Luck!

If I helped, please don't forget to accept my answer.

3 comments

0

Either that or in his original loop he would need to use v.Name or v.Price or whatever he would need to do.

0

I didn't even read the second part of his question actually

0

Thanks, yeah - could I do what I said on the second half? :D

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