Module:Dice/Format: Difference between revisions
Jump to navigation
Jump to search
(add truncated mean; minor refactoring) |
(autodetect which kind of string we wanted) |
||
Line 4: | Line 4: | ||
function DiceFormat.diceStats(frame) | function DiceFormat.diceStats(frame) | ||
local | local succeeded, result = pcall(Dice.fromRangeString, frame.args.roll) | ||
if not succeeded then | |||
result = Dice.fromDiceString(frame.args.roll) | |||
end | |||
local dice = result | |||
local templatetitle = 'Dice string' | local templatetitle = 'Dice string' |
Revision as of 16:30, 12 September 2019
local Dice = require'Module:Dice'
local DiceFormat = {}
function DiceFormat.diceStats(frame)
local succeeded, result = pcall(Dice.fromRangeString, frame.args.roll)
if not succeeded then
result = Dice.fromDiceString(frame.args.roll)
end
local dice = result
local templatetitle = 'Dice string'
if (frame.args.template ~= nil and frame.args.template ~= '') then
templatetitle = frame.args.template
end
local minimum = dice:minimum()
local mean = dice:mean()
local maximum = dice:maximum()
return frame:expandTemplate{
title = templatetitle,
args = {
minimum = minimum,
mean = mean,
mean_truncated = ('%d'):format(mean),
maximum = maximum,
},
}
end
return DiceFormat