<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nbittrpgwiki.pynappo.xyz/index.php?action=history&amp;feed=atom&amp;title=Module%3AChoose</id>
	<title>Module:Choose - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://nbittrpgwiki.pynappo.xyz/index.php?action=history&amp;feed=atom&amp;title=Module%3AChoose"/>
	<link rel="alternate" type="text/html" href="https://nbittrpgwiki.pynappo.xyz/index.php?title=Module:Choose&amp;action=history"/>
	<updated>2026-11-06T19:09:07Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://nbittrpgwiki.pynappo.xyz/index.php?title=Module:Choose&amp;diff=3266&amp;oldid=prev</id>
		<title>CStatic: Created page with &quot;local getArgs = require(&quot;Module:Arguments&quot;).getArgs;  local p = {}  -- Note to dev wiki editors: this function is copied from Module:Example. -- Changes to this function should be synced with the source. local function unescape(text) 	if not text:match(&quot;UNIQ&quot;) then 		return text; 	end 	local unescaped = mw.text.unstripNoWiki(text); 	local text, count = string.gsub(unescaped, &quot;&amp;lt;&quot;, &quot;&lt;&quot;); 	text, count = string.gsub(text, &quot;&amp;gt;&quot;, &quot;&gt;&quot;); 	text, count = string.gsub(text, &quot;&lt;/...&quot;</title>
		<link rel="alternate" type="text/html" href="https://nbittrpgwiki.pynappo.xyz/index.php?title=Module:Choose&amp;diff=3266&amp;oldid=prev"/>
		<updated>2026-10-05T01:14:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local getArgs = require(&amp;quot;Module:Arguments&amp;quot;).getArgs;  local p = {}  -- Note to dev wiki editors: this function is copied from Module:Example. -- Changes to this function should be synced with the source. local function unescape(text) 	if not text:match(&amp;quot;UNIQ&amp;quot;) then 		return text; 	end 	local unescaped = mw.text.unstripNoWiki(text); 	local text, count = string.gsub(unescaped, &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;lt;&amp;quot;); 	text, count = string.gsub(text, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;); 	text, count = string.gsub(text, &amp;quot;&amp;lt;/...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local getArgs = require(&amp;quot;Module:Arguments&amp;quot;).getArgs;&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Note to dev wiki editors: this function is copied from Module:Example.&lt;br /&gt;
-- Changes to this function should be synced with the source.&lt;br /&gt;
local function unescape(text)&lt;br /&gt;
	if not text:match(&amp;quot;UNIQ&amp;quot;) then&lt;br /&gt;
		return text;&lt;br /&gt;
	end&lt;br /&gt;
	local unescaped = mw.text.unstripNoWiki(text);&lt;br /&gt;
	local text, count = string.gsub(unescaped, &amp;quot;&amp;amp;lt;&amp;quot;, &amp;quot;&amp;lt;&amp;quot;);&lt;br /&gt;
	text, count = string.gsub(text, &amp;quot;&amp;amp;gt;&amp;quot;, &amp;quot;&amp;gt;&amp;quot;);&lt;br /&gt;
	text, count = string.gsub(text, &amp;quot;&amp;lt;//nowiki&amp;gt;&amp;quot;, &amp;quot;&amp;lt;/nowiki&amp;gt;&amp;quot;);&lt;br /&gt;
	return text;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function applyFormat(option, args)&lt;br /&gt;
	local format = args[&amp;#039;format&amp;#039;] or &amp;quot;&amp;quot;&lt;br /&gt;
	if format == &amp;quot;template&amp;quot; then&lt;br /&gt;
		local template = args[&amp;#039;template&amp;#039;]&lt;br /&gt;
		if not template then&lt;br /&gt;
			error(&amp;#039;The &amp;quot;template&amp;quot; argument must be supplied.&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		return &amp;quot;{{&amp;quot; .. template .. &amp;quot;|1=&amp;quot; .. option .. &amp;quot;}}&amp;quot;&lt;br /&gt;
	elseif format == &amp;quot;userformat&amp;quot;then&lt;br /&gt;
		local userformat = args[&amp;#039;userformat&amp;#039;]&lt;br /&gt;
		if not userformat then&lt;br /&gt;
			error(&amp;#039;The &amp;quot;userformat&amp;quot; argument must be supplied.&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		local raw = unescape(userformat)&lt;br /&gt;
		return string.gsub(raw, &amp;quot;%%s&amp;quot;, option)&lt;br /&gt;
	else&lt;br /&gt;
		return option&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getWeight(args, i)&lt;br /&gt;
	local weight = tonumber(args[&amp;quot;weight&amp;quot; .. i])&lt;br /&gt;
&lt;br /&gt;
	if weight == nil then&lt;br /&gt;
		return 1&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if weight &amp;lt; 0 then&lt;br /&gt;
		error(&amp;#039;Weight &amp;quot;weight&amp;#039; .. i .. &amp;#039;&amp;quot; must not be negative.&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return weight&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function chooseWeightedIndex(weights)&lt;br /&gt;
	local total = 0&lt;br /&gt;
&lt;br /&gt;
	for _, weight in ipairs(weights) do&lt;br /&gt;
		total = total + weight&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if total &amp;lt;= 0 then&lt;br /&gt;
		return math.random(#weights)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local r = math.random() * total&lt;br /&gt;
&lt;br /&gt;
	for i, weight in ipairs(weights) do&lt;br /&gt;
		r = r - weight&lt;br /&gt;
&lt;br /&gt;
		if r &amp;lt; 0 then&lt;br /&gt;
			return i&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return #weights&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
&lt;br /&gt;
	local container = mw.html.create(&amp;quot;div&amp;quot;)&lt;br /&gt;
	container:addClass(&amp;quot;gadget-choose&amp;quot;)&lt;br /&gt;
	&lt;br /&gt;
	local options = {}&lt;br /&gt;
	local weights = {}&lt;br /&gt;
&lt;br /&gt;
	for i, option in ipairs(args) do&lt;br /&gt;
		local weightKey = &amp;quot;weight&amp;quot; .. i&lt;br /&gt;
		local weight = getWeight(args, i);&lt;br /&gt;
&lt;br /&gt;
		local content = applyFormat(option, args)&lt;br /&gt;
&lt;br /&gt;
		local optionDiv = mw.html.create(&amp;quot;div&amp;quot;)&lt;br /&gt;
		optionDiv:addClass(&amp;quot;gadget-choose-option&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
		if weight then&lt;br /&gt;
			optionDiv:attr(&amp;quot;data-weight&amp;quot;, weight)&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		optionDiv:wikitext(content)&lt;br /&gt;
		table.insert(weights, weight)&lt;br /&gt;
		table.insert(options, optionDiv)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local selected = chooseWeightedIndex(weights)&lt;br /&gt;
	&lt;br /&gt;
	for i, option in ipairs(options) do&lt;br /&gt;
		if i ~= selected then&lt;br /&gt;
			option:css(&amp;quot;display&amp;quot;, &amp;quot;none&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
		container:node(option)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local result = tostring(container)&lt;br /&gt;
&lt;br /&gt;
	if args[&amp;#039;format&amp;#039;] then&lt;br /&gt;
		return frame:preprocess(result)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>CStatic</name></author>
	</entry>
</feed>