Module:Sandbox: Difference between revisionsGive feedback
test |
test |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local items_data = mw.loadJsonData("Data:ItemData.json") | ||
-- {{#invoke:Sandbox| | -- {{#invoke:Sandbox|get_item_key|item name}} | ||
function p. | function p.get_item_key(frame) | ||
local | local item_name_input = frame.args[1] -- Get the item name from the template argument | ||
if not | if not item_name_input then | ||
return "Error: | return "Error: Item name not specified." | ||
end | end | ||
item_name_input = item_name_input:lower() -- For case-independent search | |||
-- Go through all the | -- Go through all the items and look for a name match. | ||
for | for item_key, item_data in pairs(items_data) do | ||
if | if item_data and item_data["Name"] then | ||
local | local current_item_name = item_data["Name"]:lower() | ||
if | if current_item_name == item_name_input then | ||
return | return item_key -- Return the key if the name matches | ||
end | end | ||
end | end | ||
end | end | ||
return " | return "Item not found." -- If nothing is found | ||
end | end | ||
return p | return p | ||