Module:Sandbox: Difference between revisionsGive feedback
Blanked the page Tag: Blanking |
test |
||
| Line 1: | Line 1: | ||
local p = {} | |||
local heroes_data = mw.loadJsonData("Data:HeroData.json") | |||
-- {{#invoke:Sandbox|get_hero_key|hero name}} | |||
function p.get_hero_key(frame) | |||
local hero_name_input = frame.args[1] -- Get the hero name from the template argument | |||
if not hero_name_input then | |||
return "Error: Hero name not specified." | |||
end | |||
hero_name_input = hero_name_input:lower() -- For case-independent search | |||
-- Go through all the characters and look for a name match. | |||
for hero_key, hero_data in pairs(heroes_data) do | |||
if hero_data["Name"] then | |||
local current_hero_name = hero_data["Name"]:lower() | |||
if current_hero_name == hero_name_input then | |||
return hero_key -- Return the key if the name matches | |||
end | |||
end | |||
end | |||
return "Hero not found." -- If nothing is found | |||
end | |||
return p | |||