Anonymous
×
Create a new article
Write your page title here:
We currently have 496 articles on WIKI - Idle Pixel. Type your article name above or click on one of the titles below and start writing!



WIKI - Idle Pixel

Module:RandomText: Difference between revisions

No edit summary
Tag: Reverted
(Undo revision 53031 by Dounford (talk))
Tag: Undo
 
Line 10: Line 10:
local textArray = {}
local textArray = {}
local allText = args[1]
local allText = args[1]
return allText
for word in string.gmatch(allText, '[^\r\n]+') do
--for word in string.gmatch(allText, '[^\r\n]+') do
    table.insert(textArray, word)
    -- table.insert(textArray, word)
end
--end


--math.randomseed(os.time())
math.randomseed(os.time())
--local randomIndex = math.random(table.getn(textArray))
local randomIndex = math.random(table.getn(textArray))
--return p.pp(textArray[randomIndex])
return p.pp(textArray[randomIndex])
end
end


return p
return p

Latest revision as of 21:28, 5 December 2024

Template:RandomText is used like this:

{{RandomText <-- Template Name

|option 1 <-- You need to use a | before the first option

option 2 <-- Options are separated by new line

option n <-- There are no limit of options

}} <-- Don't forget to close the template


inspect = require("Module:InspectLua")
local p = {}

function p.pp(text)
    return mw.getCurrentFrame():preprocess(text)
end

function p.randomizeText (frame)
	local args = frame:getParent().args
	local textArray = {}
	local allText = args[1]
	for word in string.gmatch(allText, '[^\r\n]+') do
    	table.insert(textArray, word)
	end

	math.randomseed(os.time())
	local randomIndex = math.random(table.getn(textArray))
	return p.pp(textArray[randomIndex])
end

return p