Hello!
I’m trying to make random events in twine but got some issues. I understand how to do it, but there is one part I can’t figure out. Is there a way to make one event trigger at a higher chance than another? For example, I have an array with numbers in it from 1 to 10. I want the number 5 to pop up more often during the random selection than the others.
Hi there!
One solution I have used in the past is to have more numbers in the array than the options you want to have.
For example, lets assume you have 10 different passages and a goto based on the result, it could look like this:
<<set $number to random(1,10)>>
<<set $passageName to 'Passage' + $number>>
<<goto $passageName>>
All passages have an equal 10% chance to be chosen, but if I add more numbers, I could create a switch to manipulate what I want to happen with those extra results, like this:
<<set $number to random(1,11)>>
<<switch $number>>
<<case 11>>
<<set $number to 5>>
<</switch>>
<<set $passageName to 'Passage' + $number>>
<<goto $passageName>>
Now, all passages have around 9% chance to be chosen, while Passage5 has an 18% chance, because either 5 or 11 count towards it. This allows you to manipulate the chances however you want, you just have to add more cases or more options to each case, like this:
<<set $number to random(1,16)>>
<<switch $number>>
<<case 11 12 13 14 15>>
<<set $number to 5>>
<<case 16>>
<<set $number to 8>>
<</switch>>
<<set $passageName to 'Passage' + $number>>
<<goto $passageName>>
In this example, Passage5 has 31.25% chance to be chosen, Passage8 has 12.5% and all others have a 6.25% chance.
Hope this helps you, have fun!
Ah, yes! That makes sense and not as difficult as I though it would be. Thanks for the help!