Module:ItemData/nameGive feedback
Jump to navigation
Jump to search
Overview
[edit source]Retrieves the internal item key matching the specified item name.
Functions
[edit source]get_item_key(frame)
[edit source]Examples
[edit source]{{#invoke:ItemData/name|get_item_key|Stamina Mastery}}
upgrade_superior_stamina
Parameters
[edit source]item_name_input (string) - The item's display name to look up (case-insensitive)
local p = {}
local items_data = mw.loadJsonData("Data:ItemData.json")
-- {{#invoke:Sandbox|get_item_key|item name}}
function p.get_item_key(frame)
local item_name_input = frame.args[1] -- Get the item name from the template argument
if not item_name_input then
return "Error: Item name not specified."
end
item_name_input = item_name_input:lower() -- For case-independent search
-- Go through all the items and look for a name match.
for item_key, item_data in pairs(items_data) do
if item_data and item_data["Name"] then
local current_item_name = item_data["Name"]:lower()
if current_item_name == item_name_input then
return item_key -- Return the key if the name matches
end
end
end
return "Item not found." -- If nothing is found
end
return p