Module:Dice/Format: Difference between revisions

Jump to navigation Jump to search
66 bytes added ,  06:18, 25 August 2023
oops, pcall no longer necessary
(turns out these values also need to be rounded for character stats... tried making a few adjustments.)
(oops, pcall no longer necessary)
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:


function DiceFormat.diceStats(frame)
function DiceFormat.diceStats(frame)
     local succeeded, dice = pcall(Dice.from_range_string, frame.args.roll)
     local dice = Dice.parse(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 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.multiplier or 1
local mult = (frame.args.multiplier ~= nil and frame.args.multiplier ~= '') and frame.args.multiplier or 1
local extra_afterroll = (frame.args.extraafterroll ~= nil and frame.args.extraafterroll ~= '') and frame.args.extraafterroll or 0


     local average = dice:average() * mult
     local average = dice:average() * mult + extra_afterroll
     local average_truncated = ('%d'):format(average)
     local average_truncated = ('%d'):format(average)
     local maximum = dice:maximum() * mult
     local maximum = dice:maximum() * mult + extra_afterroll
     local minimum = dice:minimum() * mult
     local minimum = dice:minimum() * mult + extra_afterroll
     local range = dice:range() * mult
     local range = dice:range() * mult
     local variance = dice:variance() * mult
     local variance = dice:variance() * mult

Navigation menu