Module:Dice/Format: Difference between revisions
Jump to navigation
Jump to search
(update to be compatible with new version of Module:Dice) |
(oops should have left that name alone) |
||
Line 3: | Line 3: | ||
local DiceFormat = {} | local DiceFormat = {} | ||
function DiceFormat. | function DiceFormat.diceStats(frame) | ||
local succeeded, dice = pcall(Dice.from_range_string, frame.args.roll) | local succeeded, dice = pcall(Dice.from_range_string, frame.args.roll) | ||
Revision as of 05:08, 19 July 2020
local Dice = require'Module:Dice'
local DiceFormat = {}
function DiceFormat.diceStats(frame)
local succeeded, dice = pcall(Dice.from_range_string, frame.args.roll)
if not succeeded then
dice = Dice.from_dice_string(frame.args.roll)
end
local template_title = 'Dice string'
if (frame.args.template ~= nil and frame.args.template ~= '') then
template_title = frame.args.template
end
local average = dice:average()
local average_truncated = ('%d'):format(average)
local maximum = dice:maximum()
local minimum = dice:minimum()
local range = dice:range()
local variance = dice:variance()
return frame:expandTemplate{
title = template_title,
args = {
average = average,
average_truncated = average_truncated,
maximum = maximum,
minimum = minimum,
range = range,
variance = variance,
-- for backwards compatibility
mean = average,
mean_truncated = average_truncated,
},
}
end
return DiceFormat