Module:Sandbox: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
test
mNo edit summary
 
(21 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
This page is protected from editing. Please see [[Deadlock:User pages]].
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

Latest revision as of 21:01, 30 July 2026

This page is protected from editing. Please see Deadlock:User pages.