m (Dounford moved page Module:Random Text to Module:RandomText without leaving a redirect) |
No edit summary |
||
| Line 7: | Line 7: | ||
function p.randomizeText (frame) | function p.randomizeText (frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
-- local textArray = {} | |||
local allText = frame.args[1] | local allText = frame.args[1] | ||
-- for word in string.gmatch(allText, '([^;]+)') do | |||
-- table.insert(textArray, word) | |||
-- end | |||
-- math.randomseed(os.time()) | |||
local randomIndex = math.random(table.getn(textArray)) | --local randomIndex = math.random(table.getn(textArray)) | ||
return textArray[randomIndex] | --return textArray[randomIndex] | ||
return allText | |||
end | end | ||
return p | return p | ||
Revision as of 20:54, 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
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 = frame.args[1]
-- for word in string.gmatch(allText, '([^;]+)') do
-- table.insert(textArray, word)
-- end
-- math.randomseed(os.time())
--local randomIndex = math.random(table.getn(textArray))
--return textArray[randomIndex]
return allText
end
return p