Hello! I want to make a shop for my simulator game and i need to acces the clicked item data but first i would like to know which one of those 2 scripts are more optimized :
1 :
local Storage = {}
Storage.Items = {
{
Name = "First Item",
Price = 15
},{
Name = "Second Item",
Price = 25
}
}
function GetItemPrice(Name:string)
local ItemPrice = nil
for _,i in pairs(Storage.Items) do
if i.Name == Name then
ItemPrice = i
break
end
end
return ItemPrice
end
local itemPrice = GetItemPrice("Second Item")
2 :
local Storage = {}
Storage.Items = {
{
Name = "First Item",
Price = 15
},{
Name = "Second Item",
Price = 25
}
}
local itemPrice = Storage.Items[2].Price