Module:SS Coin

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 20:37, 7 June 2024 by Vish (talk | contribs) (Created page with "local p = {} function p.getCharacterIDs(frame) local characterName = frame.args[1] -- The character name to search for local data = mw.loadJsonData('JoJo Wiki:SS Medals') local matches = {} -- Iterate through each entry in the data for id, entry in pairs(data) do local characters = entry.character if type(characters) == "table" then -- If characters is a table, check each element for _, name in ipairs(char...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
    local data = mw.loadJsonData('JoJo Wiki:SS Medals')
    local matches = {}
    
    -- Iterate through each entry in the data
    for id, entry in pairs(data) do
        local characters = entry.character
        if type(characters) == "table" then
            -- If characters is a table, check each element
            for _, name in ipairs(characters) do
                if name == characterName then
                    table.insert(matches, id)
                    break -- Stop checking this entry if a match is found
                end
            end
        elseif type(characters) == "string" and characters == characterName then
            -- If characters is a string and matches the characterName
            table.insert(matches, id)
        end
    end
    
    -- Format the matches into template calls
    local output = {}
    for _, id in ipairs(matches) do
        table.insert(output, frame:preprocess('{{CoinS2|' .. id .. '}}'))
    end
    return table.concat(output, "\n")
end

return p