Hi all,
I've been using the posts on this forum to piece together a Twine game (I'm not a coder, as will become obvious...) I'm making to use some of my music/audio in.
I have a problem where I'm trying to generate a random number between 1 and 10, with 3 possible outcomes.
I found the following post which I thought would solve the problem:
http://twinery.org/forum/index.php/topic,1490.msg2655.html#msg2655And so set about putting it to effect. Here's the code I am using:
<<set $number = Math.floor((Math.random()*10)+1)>>
<<if $number lte 1>>
<<goto "misfire">>
<<elseif $number gte 2 or $number lte 3>>
<<goto "noeffect1">>
<<elseif $number gte 4>>
<<goto "area1bearingsuccess">>
<<endif>>
The intent is to have a 10% chance of the first outcome, a 20% chance of the second, and a 70% chance of the third; with the story progressing to the relevant passage.
The problem is that it seems to get stuck choosing the 2nd option (i.e. the number 2 or 3 has been returned).
I'm guessing this is a straight up simple mistake I'm making, but any pointers would be very much appreciated.
Thanks,
Mickey
Comments
Personally, I'd probably simply that logic a bit, like so: That's more of a personal preference thing though.
Thanks a lot for your suggestion. I ended up going with your revised code and it works a treat!
Much appreciated :-)
If it was and it took a variable for its destination...