Module:SS Medals

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

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

local p = {}

function p.getData(frame)
    -- Load JSON data directly from the page "JoJo Wiki:SS Medals"
    local data = mw.loadJsonData('JoJo Wiki:SS Medals')

    -- Retrieve the ID and parameter to return from the passed frame arguments
    local id = frame.args[1]
    local param = frame.args[2]  -- Parameter to return (e.g., title, rarity, character)

    -- Check if data for the given ID exists
    if data[id] then
        local value = data[id][param]
        -- Check if the parameter is valid and handle if it's a table (list)
        if value then
            if type(value) == "table" then
                -- Join table elements into a comma-separated string, or handle it as needed
                return table.concat(value, ", ")
            else
                -- Convert to string if necessary (for consistency)
                return tostring(value)
            end
        else
            return "Parameter not found."
        end
    else
        return "N/A"
    end
end

return p