Anonymous

Module:Items: Difference between revisions

From Melvor Idle
m
Read-only tables cause some weird issues, revert
(getItemByID/getItem/getItems: Prevent cloning of items in an attempt to conserve memory; getSpecialAttackTable: Remove unused function)
m (Read-only tables cause some weird issues, revert)
Line 68: Line 68:


function p.getItemByID(ID)
function p.getItemByID(ID)
return ItemData.Items[ID + 1]
local result = Shared.clone(ItemData.Items[ID + 1])
if result ~= nil then
result.id = ID
end
return result
end
end


function p.getItem(name)
function p.getItem(name)
local result = nil
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "'", "'")
name = string.gsub(name, "'", "'")
Line 77: Line 82:
local itemName = string.gsub(item.name, '#', '')
local itemName = string.gsub(item.name, '#', '')
if name == itemName then
if name == itemName then
return item
result = Shared.clone(item)
--Make sure every item has an id, and account for Lua being 1-index
result.id = i - 1
break
end
end
end
end
return nil
return result
end
end


Line 88: Line 96:
for i, item in ipairs(ItemData.Items) do
for i, item in ipairs(ItemData.Items) do
if checkFunc(item) then
if checkFunc(item) then
local newItem = Shared.clone(item)
newItem.id = i - 1
itemCount = itemCount + 1
itemCount = itemCount + 1
result[itemCount] = item
result[itemCount] = newItem
end
end
end
end