What would be the most efficient way to do this?

Let’s say I have something like this:

{
  {
    name = "gun",
    price = 10,
    ...
  },
 {
    name = "sword",
    price = 15,
    ...
  },
  ...
}

What would be the most efficient way of searching through this large table by name and returning the value of it?

2 Likes

Just try using table.find() Im not sure if this could help

I don’t think that would work for this.

My solution would be to loop through all the tables and check if the name matches, I think the efficiency should be fine as long as you don’t have tens of thousands of weapons. Using a dictionary to store the data instead would be another solution, e.g.

{
    Gun = {
        Price = 10,
        ...
    },

    Sword = {
        Price = 15,
        ...
    }
}

As I believe that you can just index the dictionaries.

not sure what you are trying to accomplish?
Also, you can do something like:

local sets = {
	Set1 = {
		name = "test",
		price = 15
	},
	Set2 = {
		name = "test",
		price = 10
	}
}

might be easier. What name are you trying to find?

i.e: Do you mean you would want the name of the group “Set1” (here, set as “test”)?