I'm using Twine 1.4.2 and sugarcane 2. I'd like any passages that have the [computer] tag to play a short sound (click.wav) when the user makes their selection. For passages marked [telephone], I'd like a different sound (beep.wav) to play when the player selects a choice/link.
What's the easiest way to do this?
One side issue: I've found sound effect sounds to be slightly unpredictable in my experiments where sometimes there's a significant delay (several seconds) between when I call the sound (e.g. <<audio "newmessage" play>> ) and when it actually plays. Is that a common issue? I am doing cache audio in the storyinit (e.g. <<cacheaudio "newmessage" "./assets/audio/NewMessage.wav">> )
Comments
For example, if all passage links should initiate playback, then you could do something like the following: (goes in a script-tagged passage)
In general, no. Are your audio assets being loaded from a local drive or over the network? Do they have some initial silence or are they gapless? Are you trying this in a desktop or mobile browser? Have you tried other browsers?
You did change the track IDs within the snippet to whatever they should be, or used those IDs with your <<cacheaudio>> invocations, yes?
Also, are the links within normal passages? I assumed they were, so that's where the task looks for them (well, it checks the entire story display area, but that amounts to the same thing, practically). If the links are someplace else (in the UI bar, a dialog, a custom element elsewhere), then they won't be found by the current code.
Finally, just to make sure, have you tested those tracks to ensure they're working?
1. Using the code above, it works for the first button clicked, but never again until you restart the game. This is just for a short (1sec) sound effect. Do I need to issue a stop or rewind command before playing it again?
2. The second issue is that for the passages that are using a typewriter post render function, it doesn't work. I'll experiment with coordination between the two.
Which browser are you testing this in?
If you'd care to try some debugging. In the example code I gave previously, find the following: And replace it with this: (I added some debugging code) Afterwards. Open your browser's developer console, go to one of the passages you're testing this in and click on some links to see what shows up in the console.
Depending on which "typewriter post render function" you're referring to, you may not be able to put links into it without it breaking them. Beyond that, the setupAudioOnClick task cannot patch links which do not yet exist within the DOM, so depending on how the typewriter module you're using works, the task might fire long before the typewriter puts any links where it might have been able to find them.