Print random roll outcome

Twine Version: 2.3.16
Story Format: Sugarcube
Hello, ya boy is back with another probably simple question that my dumbass can’t seem to figure out. Is there a way to print a random roll’s results in another passage?

<<if [$playerhit + random(1,5) >= $enemyevasion + random(1,5)]>>
	<<set $enemyHP to $enemyMaxHP -= $playerweapondamage + random(1,$playerStrength)>>
	<<print '$name connects with a powerful swing! $enemyname takes 		$playerweapondamage + strengthroll 1-$playerStrength damage!'>>
	<<else>>
	<<print '$name misses!'>>
<</if>>

I want to be able to show the player the results of the equation, specifically the total number that comes up when adding the weapon damage, random roll, and player strength together. Would I have to set it as its own variable?

You are already using Story Variables to track values, so use use a couple more to track the random “rolls”.

note: I’m slightly confused by your usage of square brackets within the <<if>> macro example you included. The way you are using them would cause a single element Array to be created.

eg.

<<set $roll1 to random(1,5)>>
<<set $roll2 to random(1,5)>>
<<set $roll3 to random(1, $playerStrength)>>

<<if ($playerhit + $roll1) >= ($enemyevasion + $roll2)>>
	<<set $enemyHP to $enemyMaxHP - ($playerweapondamage + $roll3)>>
	<<print '$name connects with a powerful swing! $enemyname takes $playerweapondamage + strengthroll 1-$playerStrength damage!'>>
<<else>>
	<<print '$name misses!'>>
<</if>>

Thats working perfectly, thank you!

1 Like