I’m working on a dungeon crawler and I’d like to make dice rolls against the character stats to decide success or failure. A simple “roll 1d100, check against relevant stat, if equal or lower, success. If higher, failure”.
So I got it working with a very simple:
<<link [[Roll vs Strength|Roll Result]]>>
<<set $rollstr to random(1, 100)>> <</link>>
You can use Math.max and Math.min to get the higher/lower of two rolls:
<<set $roll to Math.min(random(1,100), random(1,100))>> --> this gives you the lower of 2 rolls
<<set $roll to Math.max(random(1,100), random(1,100))>> --> this gives you the higher of 2 rolls
Also, I don’t really know your story structure, so this may not be useful to you, but if there’s significant branching depending on the results of such tests (and not just different flavour text) doing all the testing inside the <<link>> macro and redirecting to different passages may help organise the things better. It lets you use temporary variables as well, which don’t clutter your Story History:
The second code for some reason didn’t work, every time it resulted in “failure” even when it shouldn’t be possible (rolling 1d00 against 100, for example). But once I changed the temporary variable to a permanent one (the set _roll to set $roll) it worked well.