Help with random events

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2
Story Format: sugarcube 2

Hi I’m making a simple Twain game, and I add random events, let’s say I meet someone or come across a place I want to remove the place from the events and add it to the list of always places to visit. and I’m newbie.

1 Like

How have you set up “events”?

So you want a list of visited locations that become available to re-visit once they’ve occurred randomly in the story? Is your story linear, or are you creating hubs with multiple events?

1 Like

Yes, I want to visit the locations that I encountered in the events, and my story is linear, but the sandbox.

And how remove the locations after encounter?

I created a super-simple project to show how to achieve this, assuming you have a central hub passage. In it, you start at your Home and can Explore to meet people that show you the way to different places. You can only meet each person once and when you’ve met them all, the Explore option is no longer active. Also from the Home passage, you can visit all places you know the way to, as many times as you want. Once you’ve visited all three, you can go to the winning passage.

If you don’t want a hub passage, and the links to discovered locations should appear in some/all passages of your story, you can put the “for” part of the Home passage in a separate passage instead, then use <<include>> (described here: SugarCube v2 Documentation) to show it in multiple passages.

Just unzip the file attached to this post and open it in Twine to see how it’s done. Let me know if you have any questions!

random events to discover (151.3 KB)


Bro thank you so much that helps me…

Do you have more info about RPG?

How can I visit a person’s site after meeting him, can I put the person inside the forest so that I can visit him after discovering it, for example, I want to place several people inside the same forest, and I do not want to see their sites until after I have discovered them several times. Or look for weeds or something, or just do the same thing inside the forest itself to detect people, and finally like with my use of your line can I put infinite events with your method, I’m sorry for all that if I bothered you

Well, if you want to create an RPG, you’ll likely need to use variables, conditional statements (if-statements), arrays and the random() function - all of them are described in the Sugarcube documentation I linked, you can use ctrl+F to search the documentation (all are also used in my example). RPGs are not the easiest things to code in Twine, but they’re also not that difficult (especially if you start with a smaller project), and if you have a question about something in particular, you can always search this forum - lots of Twine questions are getting answered here, some are about RPGs as well. If you don’t find an answer, create a new topic and ask! You can also look up Twine tutorials on the Internet - although I don’t know of any dealing with RPG mechanics in particular, they are a good place to start, and deal with variables and if-statements, among other things.

As a reference/inspiration, here’s a list of all games tagged “twine” and “rpg” on the ifdb (3 of my own games there, too):

(just bear in mind some of them may use story formats other than sugarcube, and to recreate something you’ve seen in such a game you may need to code it differently).

As for your specific questions: you can add more events to the example game by adding them into the $events array in the StoryInit passage (eg. change it to <<set $events to ["Discover Forest", "Discover Lake", "Discover Mountain", "Discover City"]>>, then create a passage called "Discover City" - it will be available through the Explore link. In “Discover City” put <<run $locations.push("City")>> (to add City to the location list), and finally, create the City passage.

For things to do in the Forest, or other passages - you can put basically anything you want there - descriptions, links to new passages, etc. For example, in the Forest passage you can write:

You see an old man here.

[[Talk to the old man]]

If the links should only display sometimes, you’ll have to use variables (or the hasVisited() function). In the example above, if you changed it to

<<if not hasVisited("Talk to the old man")>>
You see an old man here.

[[Talk to the old man]]

then once the player has visited the Talk to the old man passage, the “Talk to…” link in Forest will no longer appear (this function checks the story history to determine if the player has seen a particular passage).

If this is your first Twine game, you may also want to take some time and start with a simple test project, just to play around with links, passages, if-statements and such, before you start working on the game you have in mind.

Hope this helps!


That what I want, thanks very much :heart:

1 Like