Audio error help in Sugarcube

If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.9
Story Format: Sugarcube 2.31.1

Hi all,

I am about tearing my hair out over this. I want to have a little sound effect play when you click a word of text. I was having trouble making that work so I tested out having any audio play whatsoever, and no matter what I do, I can’t seem to get any audio to play during the game at all.

Things I’ve tried that have not worked:

  • Linking a .wav file from Dropbox (and yes changed the dl0 to dl1), Wix, and from my own hard drive
  • Publishing the game to HTML and playing in both Safari and Chrome
  • Cacheing audio in my StoryInit passage and playing it on the second page of the game, not the starting one
  • Adding &ext=.wav to the end of the audio filename

I keep getting this error:
Error: <<audio>>: error during runner initialization: track "Rattle" does not exist

I’ve seen a couple other people with this problem (here and here among others).

I feel like I’ve tried every solution and it still doesn’t work. It seemed like this might have been a bug in Twine, but I thought it got fixed.

Does anyone know…

  • If this bug is still known to exist in the latest versions of Twine and Sugarcube?
  • If there’s ANYTHING else I can try? I find it hard to believe I’m just screwed for being able to add any audio to my game…that seems like a bug that renders a huge part of the program totally unusable.
  • If there’s a way to do this with Javascript or something - I don’t know any Javascript tbh so I’m a little nervous there.

Any help would be so incredibly appreciated. Thank you.

Dredging up threads from the Twinery forums or Q&A is, generally, always a bad idea. They’re usually woefully out of date, as in this case.

What, exactly, are you trying? In other words, show your code.

  1. Show your <<cacheaudio>> invocation.
  2. Show your <<audio>> invocation.

Thank you for the reply!! The old forums had been super helpful for me in the past, but in this case I am just running into dead end after dead end. A few things I’ve tried:

The cache code:
<<cacheaudio "Rattle" "">> with and without the &ext=.wav
I’ve also tried
<<cacheaudio "Rattle" "">>
<<cacheaudio "Rattle" "/Audio/chain.wav">> from my computer.

For the audio part:
<<audio "Rattle" play>>

The ultimate goal is to a) be able to play music throughout the game and b) trigger a specific sound effect when the player clicks a word of text, but I haven’t really dived into b yet since I’m having so much trouble with a.

Running <<cacheaudio "Rattle" "">>, or the same without the “&ext=.wav” part, both give me a 403 “Forbidden” error, so those won’t work. (Open your browser’s Developer Tools window and look in the Console section to see such errors.)

However, <<cacheaudio "Rattle" "">> works just fine for me in the Opera browser, with SugarCube v2.35.0, with the browser tab unmuted, and when called from within the following code:

<<button "Rattle">>
	<<audio "Rattle" play>>

Loading the audio file from your computer should also work fine, provided that you have the full path to the file correct (which it definitely won’t be if you’re launching the game from the Twine editor using the code you gave). You’ll have to publish the game to the same directory as that “Audio” directory is in and then play that in your browser for the path to be correct (and capitalization matters on iOS, so make sure the capitalization in your code matches the actual directory and file name capitalizations). (See the “Music” section of my Twine/SugarCube sample code collection if you want to see how to make that code work, regardless of whether you’re launching it from the Twine editor or using the published HTML file.)

What code triggers the <<audio>> macro in your code? (A timer? A button? A link? Simply entering the passage?) If playing it is delayed too long after the user interacts with the page, then that might be why it isn’t working.

Also, why are you using a WAV file? I’d strongly recommend using MP3 files instead, as they are much smaller files and are much more broadly supported (some compressed WAV file formats need certain audio codecs to be available to work).

Anyways, I hope that helps narrow down the problem. :slight_smile:

HiEv covered most of the high points, so I’m just going to add some commentary on what you tried.


And that’s why the Twinery’s abandoned forums are a hazard at least as often as not. The extension hack (i.e., &ext=.ext) is just that, a hack that was a temporary fix.

The <<cacheaudio>> docs explain what to do for URLs that do not end in an audio extension.

In rare cases where the audio format cannot be automatically detected from the source (URLs are parsed for a file extension, data URIs are parsed for the media type), a format specifier may be prepended to the front of each source to manually specify the format (syntax: formatId| , where formatId is the audio format—generally, whatever the file extension would normally be; e.g., mp3, mp4, ogg, weba, wav).

In other words, it should have looked like the following:

<<cacheaudio "Rattle" "wav|">>

That said, that URL doesn’t work correctly according to HiEv, so that would definitely be part of the problem.


Works for me, and HiEv.


That’s an absolute path.

If you have an Audio directory at the root of your drive, then carry on—n.b., if you’re on Windows, you’ll probably also need to specify the drive letter.

OTOH. If the Audio directory is a sibling of your HTML file, then you’ll want to drop the initial slash to make the path relative.

Thank you for the reply! I updated my Sugarcube to 2.35 because I was using 2.31. I threw out the Dropbox link, since that doesn’t work. Now when I try it using your button code, I get the same error but in a different way.

In Safari, instead of an error on the page itself, I get a pop-up that says An error has occurred. You may be able to continue, but some parts may not work properly. Error: Script error.. and the developer tools button in the browser window is grayed out so I can’t click it.

In Chrome, I get this error as a pop-up (wouldn’t let me highlight the text to copy so I screenshotted):

And then when I open the Chrome developer tools, I see this error:

I’m on a Mac so I need the game to work in either Safari and/or Chrome.

When I take out the button code and just try to have the audio play when the player enters that passage (no delay), I get this same error I was getting before on the page itself:

I’m just using WAV because it’s what the sound effect was when I downloaded it, but I can convert it to MP3 if that might help.

Okay I found the problem…my StoryInit passage was called “Story Init” instead of “StoryInit”.


I’m going to go stick my head in a hole for awhile. Thank you so much for the detailed reply and apologies for wasting your time!

Okay, one more question, I swear.

How do I trigger the sound effect from a text link in the passage instead of a button? Like in a paragraph of normal text, a player clicks on the word to hear the sound effect.

Thank you very much for checking!! I found the initial problem that was nothing but extreme idiocy on my part - but I have one more question. How do I trigger the sound effect from a text link in the passage instead of a button? Like in a paragraph of normal text, a player clicks on the word to hear the sound effect.

EDIT: Never mind, answered below. Thanks again for your help, much appreciated!

You can do that using a <<link>> macro like this:

The dice <<link "rattled">><<audio "Rattle" play>><</link>> in the cup.

However, that will look like a link to go to another passage, which could confuse the people trying to play your game. I’d recommend styling it so that it’s obvious that it’s not a link and that it plays audio. For example:

The dice <span class="sound"><<link "rattled">><<audio "Rattle" play>><</link>></span> in the cup.

and then add the following CSS to your game’s Stylesheet section:

.sound a {
	color: inherit !important;
	text-decoration: underline dotted 1px white;
.sound a::after {
	content: "\00a0\e84c";
	font-family: tme-fa-icons;
	font-style: normal;
	font-weight: 400;
	font-variant: normal;
	text-transform: none;
	line-height: 1;
	speak: none;

Now the link will look like normal text, but with a dotted underline and a little “speaker” icon after it.

Hope that helps! :slight_smile:

This is amazing! I love that look and never would’ve thought or known how to do it. Thank you so much!!