How-To: Apply dice rolls in Harlowe 3


One of the features of this project was a section that used random dice rolls to decide whether the player's actions succeeded or failed. This is the code I used for that:

(set: _roll to (random: 1, 20))\
(if: _roll < 11)[The magic sparkles and... then dies in your hands. Dang it. You really need more practice with spellcasting.](else:)[You successfully cast a spell of fear and set it at the <span style="color:darkred;">man</span>. He cringes, suddenly feeling an onset of anxiety. That should bother him a lot. (set: $manAnnoyance to it + 6)]
[[Continue|Begin scaring him off]]

The steps are:

  1. Set up a temporary variable to hold the result of the roll. (You could use a global variable, but since I wasn't going to use the roll result outside of the passage, I used a temporary one called _roll.)
  2. Decide what die you want the code to roll for. Mine was between 1 and 20, or a d20.
  3. Set up an if/else statement based on the result of the roll. In this case, if the roll was 10 or under, the failure text would display. Otherwise, the success text would display.
  4. (Optional) Add a variable change to the success text. In this case, succeeding the roll made the man more annoyed. ('it' is just a shortcut for the variable name. You could also write the variable name in place of 'it'.) Make sure it's inside the else brackets so that it doesn't trigger if the player rolls a failure.

That's about it! More help on dice rolls can be found here. https://twinery.org/cookbook/dicerolling/harlowe/harlowe_dicerolling.html

Leave a comment

Log in with itch.io to leave a comment.