Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Having an event happen 4/50 times (Harlowe)

So I want what is happening to happen only 4/50 times. What I have to do to get something to happen this often is this:
(set: $random to (random: 1,50))
	
    (if: $random is 1)[ (display: "AA") ]
    (if: $random is 2)[ (display: "AA") ]
    (if: $random is 3)[ (display: "AA") ]
    (if: $random is 4)[ (display: "AA") ]

Is there an easier way to do this?

Comments

  • Certainly.

    First, take a look at the Twine 2 syntax guide, particularly the TwineScript Operators section, here: http://twine2.neocities.org/

    Specifically, for this you'd want to use a "less than or equal to" operator.

    I tested the following code and found it to work:
    (set: $random to (random: 1,50))
    
    (if: $random <= 4)[(display: "AA")]
    (else:)[(display: "BB")]
    
    $random
    

    Hope that helps!
  • That helps a little bit, but if I wanted to add another event that happens 3/50 times, how would I do that. I'm guessing it would be something like this:
    (set: $random to (random: 1,50))
        
            (if: $random <= 4)[ (display: "AA") ]
    	(if: 5 <= $random <= 7)[ (display: "BB") ]
            (else:)[ (display: "CC") ]
    

    However, this doesn't work. Do you have any idea how I would do this?
  • You have two choices:

    1. Checking Increasingly larger values.
    The following works because if $random is greater then 4 then the first condition will not be true, so the second condition is checked.
    (set: $random to (random: 1,50))
    
    (if: $random <= 4)[(display: "AA")]
    (elseif: $random <= 7)[(display: "BB")]
    (else:)[(display: "BB")]
    
    2. Checking a range.
    (set: $random to (random: 1,50))
    
    (if: $random <= 4)[(display: "AA")]
    (elseif: $random > 4 and $random <= 7)[(display: "BB")]
    (else:)[(display: "BB")]
    
  • Thank you!
Sign In or Register to comment.