How-To: Apply dice rolls in Harlowe 3
Fairy Forest Chores » Devlog
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:
- 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.)
- Decide what die you want the code to roll for. Mine was between 1 and 20, or a d20.
- 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.
- (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
Fairy Forest Chores
A short game about a fairy maintaining her forest.
Status | Released |
Author | Aoapp |
Genre | Interactive Fiction |
Tags | Animals, Fairy Tale, Pixel Art, Short, Twine |
Languages | English |
Accessibility | High-contrast |
Leave a comment
Log in with itch.io to leave a comment.