Jump to content

📢 Please make sure to read our Style Guide before editing. For questions, suggestions, or technical issues, please contact Noah.

Module:ButtonBox: Difference between revisions

From CrabCraft Wiki
testing cargo functionality
setup button box for variable players
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo


function p.buttonbox()
function p.buttonbox()
local query = mw.ext.cargo.query(
local tables = 'player_data'
"avatars",
local fields = 'username'
"name, image, link, label",
local args = {
{
orderBy = 'username ASC',
limit = 100,
limit = 100 -- Optional; remove or increase if needed
orderBy = "name"
}
}
)


local out = {}
local results = cargo.query(tables, fields, args)
table.insert(out, '{| class="buttonbox"')
local out = {}
local out = {}
table.insert(out, '{| class="buttonbox"')
table.insert(out, '{| class="buttonbox"')


for i, row in ipairs(query) do
for i, row in ipairs(results) do
if (i - 1) % 4 == 0 then
if (i - 1) % 4 == 0 then
table.insert(out, '|-')
table.insert(out, '|-')
end
end


local image = row.image
local image = 'https://mc-heads.net/avatar/'..row.username..'/150.png'
local label = row.label or row.name
local label = row.username
local link = row.link or ("[[User:" .. row.name .. "]]")
local link = "[[" .. row.username .. "]]"


local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..label..'</div> </div>'
local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..label..'</div> </div>'

Revision as of 15:03, 24 June 2025

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

local p = {}
local cargo = mw.ext.cargo

function p.buttonbox()
	local tables = 'player_data'
	local fields = 'username'
	local args = {
		orderBy = 'username ASC',
		limit = 100 -- Optional; remove or increase if needed
	}

	local results = cargo.query(tables, fields, args)
	local out = {}
	table.insert(out, '{| class="buttonbox"')

	for i, row in ipairs(results) do
		if (i - 1) % 4 == 0 then
			table.insert(out, '|-')
		end

		local image = 'https://mc-heads.net/avatar/'..row.username..'/150.png'
		local label = row.username
		local link = "[[" .. row.username .. "]]"

		local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..label..'</div> </div>'

		table.insert(out, cell)
	end

	table.insert(out, '|}')
	return table.concat(out, '\n')
end

return p