diff --git a/inc/functions.php b/inc/functions.php
index 9c956cda..72e6afaa 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -2813,6 +2813,17 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6;
}
+ $tot = $dice_offset;
+ for ($i = 0; $i < $dice_count; $i++) {
+ $tot += mt_rand(1, $dice_faces);
+ }
+
+ if ($img_path !== null) {
+ $img_text = "
";
+ } else {
+ $img_text = '';
+ }
+
if ($dice_offset === 0) {
$dice_offset_text = '';
} elseif ($dice_offset > 0) {
@@ -2821,21 +2832,7 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_offset_text = (string)$dice_offset;
}
- if ($img_path !== null) {
- $text = "
";
- } else {
- $text = '';
- }
-
- $text .= " {$dice_count}d{$dice_faces}{$dice_offset_text} =";
- for ($i = 0; $i < $dice_count; $i++) {
- $res = $dice_offset + mt_rand(1, $dice_faces);
- $text .= " $res";
- }
-
- $text .= '';
-
- return $text;
+ return "$img_text {$dice_count}d{$dice_faces}{$dice_offset_text} = $tot";
}
function slugify($post) {