This tutorial will teach you how to add sound to your Twine game.
The easiest way to do this is to first cache the sound you want to use. This means that the sound effect will be loaded ahead of time and used when you want it to. This will prevent any delay in it playing and makes it easier to keep things organized as it allows you to name your sound clips.
First, to cache the sound you must add the following code: <<cacheaudio “name of sound effect” “the URL of your sound effect”>> to one of your passages. It makes most sense to add it to the StoryInit passage so the effect will load asap, as seen below.
Next, put the URL of the sound effect you wish to use in the code where it says “the URL of your sound effect” and the name you want to give your sound effect where it says “name of sound effect”. Pretty self explanatory, but here’s a visual using “cats meowing” as the name and “http://www.ousob.com/wavfiles/meow.wav” as the URL for the sound effect:
Now you can use the sound effect wherever you please. To do so, choose a passage you want to have the sound effect occur at and put in this code: <<audio “name of sound effect”>>. Change the “name of sound effect” to the name of the sound effect you just cached. Following the example, I posted <<audio “cat-meowing”>> into Untitled Passage 1.
And that’s it! Happy Twining!