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?
Yes… and no. What you can do is have the bear appear randomly by placing the text in the passage using the either() function. You can have it print one of several pieces of text, randomly assigned by the computer. One of those pieces of text could be about the bear.
So it would look like <<print either(“You are walking through the woods and a bear appears”, “You are walking through the woods and feel something lurking nearby”, “You are walking through the woods, staring at the trees”)>>
But what if you want the game to remember that you’ve seen the bear and once you see the bear, you go off in a certain direction? Then you need to link the bear to a certain passage, use variables to assign the bear a value, and then have text that constantly checks the value of the bear from there forward.
The way you use links with random print:
You are walking through the woods and feel something [[lurking nearby|either(“Bear Here”, “No Bear”)]]
The Bear Here passage will take the player on a route where the bear appears, etc. The No Bear passage will take the player on a route without the bear. Though they could always encounter the bear later by placing the option in the game again.
I answered the OPs question on the Twine forum, but just in case anyone is reading this, it is really simple in SugarCube:
<<set $dice to random(1, 6)>>
<<if $dice is 6>>Bear!<>