Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Cookbook: Do one random action of many

Matt Peterson edited this page Dec 8, 2013 · 1 revision

This code creates what is called a weighted switch. It picks an action randomly. Actions with a higher weight have a higher chance of being executed.

- 'set.$choice': 'roll(5)' # this 5 should be the total of all the weights

#first action
- 'if $choice >= 0 and $choice < 3':
    - 'do whatever you want here'
- 'set.$choice': '$choice - 3' # same as weight above

#second action
- 'if $choice >= 0 and $choice < 2':
    - 'do whatever you want here'
- 'set.$choice': '$choice - 2' # same as weight above
Clone this wiki locally