(Twine) Advanced Interactivity
Estimated Time Investment : 90 minutes
Probability and Chance (numbers)
As game designers, we sometimes want to make a game act randomly. For instance, perhaps if the player decides to cross a river, we would like to give players a 50/50 chance to make it or be swept away to a new area.
- Download this sample coinflip game. Import it into Twine.
- Examine the four passages briefly
- Play the game several times (or watch it be played here).
- Look at the “Flip the coin” passage.
If you’ve done the logic adventure tutorial, you already know what variables are (if not, find the “variables” section and read it quickly)–
- The line “«set $random_number to random(1,10)»” is placing a number into the “$random_number” variable. Which number? A number between 1 and 10!
Once we have placed a number into the “$random_number” variable, we can check its value to do different things!
Read the text above– can you guess what’s happening?
- The line “«if $random_number > 5»” checks to see if our random_number variable is above 5. If it is, we do the following two lines (until we hit “«else»”
- If our random_number variable is 5 or below, we do the two lines after “«else»” until we hit “«endif»”
In C++, this would be equivalent to–
Probability and Chance (strings / words)
Just like how the “random()” function gives us a number, the “either()” function can give us a string (also known as a word or piece of text).
Examine the following code–
It results in this gameplay.
- Note how the compliment changes every time we play– it is randomly chosen from the list we provided to the “either()” function.
The chosen piece of text above is placed into the “$compliment” variable. This variable is then placed into the dialogue–
Video Embedding
Video can be a powerful tool for creating immersive moments in your twine game. We may embed videos using the standard HTML “video” element.
Finding Videos
You may find royalty-free .MP4 videos at websites such as pexels.com
Embedding Videos
- Play the staff-made sample game here, in which one flies around to various cities as a kite.
-
Download the project files here to see how it works.
- Visit the Chicago passage–
-
The “video” block above is what creates the embedded video–
-
The most important thing to note is the “src” tag, (where you see “chicago.mp4”– the name of your video file).
Videos may not play properly if they are in the first passage, so please be sure to embed them elsewhere.
Packaging the videos
Your videos won’t work properly until you upload them to itch.io (or someplace else, like imgur). Follow this process–
- Add all of your videos to a new folder, like so.
- Publish your twine game into this folder (with the name “index.html”) like so.
- Create a .zip file from this folder (this is what you will upload to itch.io).
Extra Video Features
- Additional Feature : One can remove the “autoplay” text, and the video will not start playing right away.
- Additional Feature : One can add the text “controls” in order to let the player scroll the video back and forth.
Process Exercise Requirements
[ ] Create a short new game on itch.io
[ ] This game must have at least one video embedded into it.
[ ] This game must have at least one instance of a random / chance event.