Module:TableGenerator: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
Sur (talk | contribs)
test
 
Sur (talk | contribs)
mNo edit summary
Line 3: Line 3:
function p.generateTable(frame)
function p.generateTable(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local output = {}
      
     local row = {}
      
 
     return #args
     for i = 1, #args / 2 do
        local statName = args['stat_name' .. i]
        local statValue = args['stat_value' .. i]
 
        if statName and statValue then
            table.insert(row, '<td>' .. statName .. ' ' .. statValue .. '</td>')
           
            -- Every 3rd entry creates a new row
            if #row == 3 then
                table.insert(output, '<tr>' .. table.concat(row) .. '</tr>')
                row = {}  -- Clear row for next set of values
            end
        end
    end
 
    -- Handle remaining cells (if not divisible by 3)
    if #row > 0 then
        while #row < 3 do
            table.insert(row, '<td></td>')  -- Fill remaining cells with empty
        end
        table.insert(output, '<tr>' .. table.concat(row) .. '</tr>')
    end
 
    return table.concat(output)
end
end


return p
return p

Revision as of 02:53, 14 September 2024

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

local p = {}

function p.generateTable(frame)
    local args = frame:getParent().args
    
    
    return #args
end

return p