Module:Dice/Format: Difference between revisions
Jump to navigation
Jump to search
(oops should have left that name alone) |
imported>Ontoclasm m (Add a 'multiplier' field to Dice/Format) |
||
Line 10: | Line 10: | ||
end | end | ||
local template_title = (frame.args.template ~= nil and frame.args.template ~= '') and frame.args.template or 'Dice string' | |||
local mult = (frame.args.multiplier ~= nil and frame.args.multiplier ~= '') and frame.args.mult or 1 | |||
local average = dice:average() * mult | |||
local average = dice:average() | |||
local average_truncated = ('%d'):format(average) | local average_truncated = ('%d'):format(average) | ||
local maximum = dice:maximum() | local maximum = dice:maximum() * mult | ||
local minimum = dice:minimum() | local minimum = dice:minimum() * mult | ||
local range = dice:range() | local range = dice:range() * mult | ||
local variance = dice:variance() | local variance = dice:variance() * mult | ||
return frame:expandTemplate{ | return frame:expandTemplate{ |
Revision as of 01:36, 4 December 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 = (frame.args.template ~= nil and frame.args.template ~= '') and frame.args.template or 'Dice string'
local mult = (frame.args.multiplier ~= nil and frame.args.multiplier ~= '') and frame.args.mult or 1
local average = dice:average() * mult
local average_truncated = ('%d'):format(average)
local maximum = dice:maximum() * mult
local minimum = dice:minimum() * mult
local range = dice:range() * mult
local variance = dice:variance() * mult
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