zCrxtix
(zavier)
November 15, 2023, 11:02pm
#1
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
iagoStorm
(iagoStorm)
November 15, 2023, 11:18pm
#2
Just try using table.find() Im not sure if this could help
zCrxtix
(zavier)
November 16, 2023, 12:25am
#3
I don’t think that would work for this.
Weiomg2020
(Weiomg2023)
November 16, 2023, 12:38am
#4
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.
dev_Typ
(Typ)
November 16, 2023, 2:57am
#5
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?
dev_Typ
(Typ)
November 16, 2023, 2:58am
#6
i.e: Do you mean you would want the name of the group “Set1” (here, set as “test”)?