Module:SS Coin

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 20:39, 7 June 2024 by Vish (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:SS Coin/doc

local p = {}

function p.getCharacterIDs(frame)
    local characterName = frame.args[1] -- The character name to search for
    if not characterName or characterName == '' then
        return "No character name provided." -- Return a message if no character name is given
    end

    local data = mw.loadJsonData('JoJo Wiki:SS Medals')
    local matches = {}
    
    for id, entry in pairs(data) do
        local characters = entry.character
        if type(characters) == "table" then
            for _, name in ipairs(characters) do
                if name == characterName then
                    table.insert(matches, id)
                    break
                end
            end
        elseif type(characters) == "string" and characters == characterName then
            table.insert(matches, id)
        end
    end

    if #matches == 0 then
        return "No matches found for " .. characterName -- Return a message if no matches are found
    end

    local output = {}
    for _, id in ipairs(matches) do
        table.insert(output, frame:preprocess('{{CoinS2|' .. id .. '}}'))
    end
    return table.concat(output, "\n")
end

return p