Please remember that WiKirby contains spoilers, which you read at your own risk! See our general disclaimer for details.

Module:DYK

From WiKirby, your independent source of Kirby knowledge.
Jump to navigationJump to search

A version of {{DYK}} that doesn't use #var. Pulls the facts from Module:DYK/facts. Use by typing {{#invoke:DYK|random}}.


--[[
	This module throws a random fact from Module:DYK/facts on every page refresh.
	If you can somehow spot server-side performance issues because of this
	module, please contact tech support.
]]--
local d = {}
local result = {}
local lang = mw.language.getContentLanguage()

function d.random ()
	-- The list of facts
	local z = require('Module:DYK/facts')
	
	-- Generates a seed with the current server time.
	math.randomseed(os.time())

	-- Needs to be a separate variable for each, because it will interpret
	-- each variable as a single instance.
	local fact1 = z[math.random(1,#z)]
	local fact2 = z[math.random(1,#z)]
	local fact3 = z[math.random(1,#z)]
	
	table.insert(result, '<ul><li>'.. fact1 ..'</li><li>'.. fact2 ..'</li><li>'.. fact3 ..'</li></ul>')
	return table.concat(result, '')
end

return d