×
Create a new article
Write your page title here:
We currently have 22 articles on The Grand Library of Hylia. Type your article name above or click on one of the titles below and start writing!



The Grand Library of Hylia

Module:RandomCargoRecord

Revision as of 06:31, 27 December 2023 by ZoeySaurusRawr (talk | contribs) (Created page with "local p = {} local h = {} local cargo = mw.ext.cargo function p.RandomCargoRecord(frame) local getArgs = require('Module:Arguments').getArgs local tableName = h.parseArg(frameArgs[1]) if tableName == nil or tableName == "" then hasErrors = true h.warn("<code>tableName</code> parameter is required") end if hasErrors then return CATEGORY_INVALID_ARGS end local countFields = 'COUNT(*)=total' local countArgs = {} local countResults =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

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

function p.RandomCargoRecord(frame)
    local getArgs = require('Module:Arguments').getArgs
    local tableName = h.parseArg(frameArgs[1])

    if tableName == nil or tableName == "" then
        hasErrors = true
        h.warn("<code>tableName</code> parameter is required")
    end
    if hasErrors then return CATEGORY_INVALID_ARGS end

	local countFields = 'COUNT(*)=total'
	local countArgs = {}
	local countResults = cargo.query(tableName, countFields, countArgs)
	local total = countResults.total

	local queryFields = 'game,link'
	local countOffset = math.random(1, total)

	local args = {
		format = table,
		fields = queryFields,
		limit = 1,
		offset = countOffset
	}
	local result = cargo.query(tableName, fields, args)
    for r = 1, #results do
        local result = results[r]
        return string.format("<h1>%s</h1>", result.link)
    end
end