Howdy, Stranger!

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

Can You Create Random Events in Twine?

I have what is maybe a weird question/request.  I've been working on the concept and storyline of my game for a while now with the attitude of "Write it now, worry about execution later" because I knew I'd get too overwhelmed and scared of limitations if I thought about the coding XD But now I'm almost done with the text, just wrapping up a few loose ends, and looking at putting things together. 

I've more or less figured out how to keep track of variables and if/else statements, so that feels like a triumph :) But here's my question!

Is there a way to create a "random event" in Twine? 

So as an example: You're walking through a forest, and a bear appears.  But the bear doesn't always appear at the same time/after the same passage from one play-through to the next.  In fact, every time you click on a passage, you have some small chance of the bear passage appearing.

The idea would be to make it startling and intrusive -- sort of the textual equivalent of jump-scare. 

Is this possible?  How would I set that up? 

Comments

  • You need to state which story format you are using, as answers can very depending on the one you use.
  • Here's how I create random events in SugarCube (this example assumes a 1 in 6 chance):

    <<silently>>
    <<set $variable to random(5)>>
    <<if $variable is 0 do stuff>><</if>>
    <<if $variable is 1 do stuff>><</if>>
    <<if $variable is 2 do stuff>><</if>>
    <<if $variable is 3 do stuff>><</if>>
    <<if $variable is 4 do stuff>><</if>>
    <<if $variable is 5 do stuff>><</if>>
    <</silently>>

    You can use javascript to then roll variable on every passage, or only passages tagged with a specific tag. You can also condense all the <<if>> statements into the one widget.

    Or if you don't want things to happen every result:

    <<set $variable to random(5)>>
    <<if $variable is 0 do stuff>><</if>>
    The important thing to remember is that 0 is a number too, so the random function will roll 0 at some times. If that bothers you you can always just say <<set $variable to random(5) + 1>>.
  • Claretta wrote:

    The important thing to remember is that 0 is a number too, so the random function will roll 0 at some times. If that bothers you you can always just say <<set $variable to random(5) + 1>>.


    Or, you could simply specify the min parameter, as noted in the random() function's documentation.  For example:

    Return a number in the range: 16 (inclusive)
    random(1, 6)
  • That is so much easier than I had expected!

      ;D I think I can manage this.  Thank you guys!
Sign In or Register to comment.