0 votes
by (180 points)

Sugarcube 2.21, Twine 2.2.1

I'm using Twine for the first time and I'm doing a simple story involving rolling a die. I have 4 options for the first roll and I want to have one sound effect play per outcome.

Here's how I cached the sounds (in StoryInit):

<<cacheaudio "fanfare" "audio\fanfare.mp3">>

<<cacheaudio "sadtrombone" "mp3|https://www.dropbox.com/s/d2k52n7xcfk1a51/notr__sadtrombones.mp3?dl=1">>

and how I'm trying to play them:

<<if $dieState eq 1>>
<<audio "crash" volume 1 play>>
Crap! You tossed it a little too hard and the die goes flying off the side table.

I first tried to use dropbox links but tested local files as well, and neither are working for me. I'm not getting any error messages but clearly something isn't right. The local files were originally in the same folder as the html (Twine2\pub2file), but I put them in a subfolder later and I don't think it changed anything. Thanks for any help!

1 Answer

+1 vote
by (44.1k points)

I don't know if the DropBox link can actually work, since that's not a direct link, it actually redirects to the download.

That said, your problem with local files is probably that you're using "\" (backslash) instead of "/" (slash).  The backslash actually has a special meaning in strings (as a kind of escape character), so for file paths you have to use the "forward" slash character.

If you want the audio to work from within Twine, then you'll have to give it an absolute path when running inside Twine.  I have some audio sample code here which shows how to do that, and also lets you know about a few other problems you may encounter.  You can also download that HTML file (plus the audio file) and import it into Twine 2 if you want to see how it works that way.

You also might want to update to the latest version of SugarCube (currently v2.28.2), since some nice new audio features were added, such as being able to have the audio automatically mute/unmute itself when the window isn't/is visible.  (Installation instructions are here if you need them.)

Hope that helps!  :-)

by (180 points)
Thanks! The backslash was messing things up for me. That sample code looks really useful too, I appreciate it!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...