Relative Audio not working in published file for Twine 2 Sugarcube 2.34

Hello I am making a twine 2 game in Sugarcube 2.34. I want an audio bgm to play in the first passage, however when I publish my game to a file the sound does not play.

I have in my StoryInit passage
<<cacheaudio “void” “425050__bruce965__loneliness.flac”>>

Then in my first passage I have the audio play using

<<audio “Void” play>>

Is my syntax incorrect?

Thanks.
Ps. I have my relative audio in the same folder as my published file.

For security reasons (read: in order to block annoying scam ads) most modern browsers automatically block audio unless you’ve already interacted with the page first.

Thus, generally it’s best to have some sort of opening “splash” screen first, and then only start playing any audio in the passages after that, since the user will have to interact with the page to get to that next passage.

If that doesn’t work, you should start your game, open the Developer Tools window (F11 or CTRL+SHIFT+I in most browsers), and then look in the Console window to see what errors are reported there.

Also, while you can use FLAC audio in most browsers (currently ~%95.58 support, i.e. a bit over 1 in 20 will have a problem with it), I’d strongly recommend using MP3 instead (currently ~98.38% support, i.e. less than 1 in 60 will have a problem with it), as it’s much better supported. It’s best to save yourself and your users that extra bit of potential problems, assuming you plan on having 20+ users.

See the “Music” section of my Twine/SugarCube sample code collection for other details and suggestions regarding playing audio in your Twine/SugarCube games.

Hope that helps! :slight_smile:

2 Likes

Thank you for the advice. I tried putting <<audio “void” play> on a splash screen, but it still does not play sound on the passage after that. In case the error was an audio format problem I tested a mp3 audio file but still no sound played. When I used dev tools I found that this was the error associated with the problem: “runner initialization: track “Void” does not exist”. I’m not sure if it will help but I am using a chrome browser to execute my file.

The track ids are case sensitive. “void” and “Void” are not the same thing. You’re loading one and then trying to play the other, which doesn’t exist?

omg you are right XD. Thank you so much.