Module:CoinDisplay: Difference between revisions
From IdleOn MMO Wiki
Kiokurashi (talk | contribs) mNo edit summary |
Kiokurashi (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function rev(tab) | |||
local new = {} | |||
for i = 0, #tab do | |||
new[#new+1] = tab[#tab-i] | |||
end | |||
return new | |||
end | |||
function p.Main(frame) | function p.Main(frame) | ||
Line 24: | Line 32: | ||
coininc = coininc + 1 | coininc = coininc + 1 | ||
until(n == 0) | until(n == 0) | ||
ret = rev(ret) | |||
return table.concat | return table.concat(ret, " ") | ||
end | end | ||
return p | return p |
Revision as of 07:17, 10 March 2024
Documentation for this module may be created at Module:CoinDisplay/doc
local p = {}
local function rev(tab)
local new = {}
for i = 0, #tab do
new[#new+1] = tab[#tab-i]
end
return new
end
function p.Main(frame)
local n = tonumber(frame.args.coins)
local ret = {}
local coins = {"Copper", "Silver", "Gold", "Platinum", "Dementia", "Void", "Lustre", "Starfire", "Dreadlo", "Godshard", "Sunder", "Tydal", "Marbiglass", "Orberal", "Eclipse"}
local coininc = 1
local stringpiece = [=[[[File:%s Coin.png|link=]] %s]=]
repeat
-- Set denomVStr to remaining n if on last type, or get last 2 for current denom.
local denomV = n
if coininc < #coins then
denomV = denomV % 100
end
if denomV > 0 then
ret[#ret+1] = string.format(stringpiece, coins[coininc], tostring(denomV))
end
if coininc < #coins then
n = math.floor(n / 100)
else
n = 0
end
coininc = coininc + 1
until(n == 0)
ret = rev(ret)
return table.concat(ret, " ")
end
return p