I'm wondering if there is a way to play a sound when a link is clicked on. I've achieved this two different ways in the past:
by simply putting <<playsound>> on the next page, or by using the <<continue>> macro. Unfortunately, neither way will work for me in a specific situation.
On a previous story, I needed to make a .gif into a link. I eventually found a solution using (someone else's) javascript:
<map id="buttonmap" name="buttonmap">
<area shape="rect" coords="0,0,100,100" "href="#" onclick="javascript:state.display('PART_ONE', this);return false;"/>
Basically, it tells twine to go to 'PART_ONE' when the mouse is clicked in the area of the button .gif. Does anyone know if this could be tweaked to use the <<playsound>> macro?
I'm trying to add sound effects to actions chosen by the player, in this case drawing or sheathing a sword. Here's the code I'm working with:
<<if $sword is "sheathed">>[[Draw your sword.|previous()][$sword = "drawn",$hands_free -=1]]<<endif>>
<<if $sword is "sheathed">>[[Let the blade rest.|previous()]]<<endif>>
<<if $sword is "drawn">>[[Sheathe your sword.|previous()][$sword = "sheathed",$hands_free +=1]]<<endif>>
<<if $sword is "drawn">>[[The blade's work is not yet done.|previous()]]<<endif>>
Since this is a "menu" item that can be accessed at any time, I don't think it is possible to put the <<playsound>> code on another page. Yet the sound should only be played after the player has chosen the appropriate link. Argh.
I wish we could just put macros inside links... [[Draw your sword|previous()][<<playsound 'sword_draw.mp3'>>]] would be amazing. Alas...
Comments
The actual solution is to do this: Assuming you're using built-in images.
One way you can accomplish this is to use a <<replace>> containing both <<playsound>> and <<goto>>: Though, this topic does suggest a further development for my HTML5 macros: function forms of playsound and stopsound for exclusive use in link tails. Hmmm.
One way you can accomplish this is to use a <<replace>> containing both <<playsound>> and <<goto>>: Though, this topic does suggest a further development for my HTML5 macros: function forms of playsound and stopsound for exclusive use in link tails. Hmmm.
Oh cool, hadn't thought of using <<replace>>. Will have to give that a try.
I'm not actually using images at the moment, I just remembered the 'on click" javascript I'd found for use in a different situation, and wondered if it could be tweaked to a new purpose. Sadly, I've yet to learn any Javascript yet. (I'm still working my way through CSS on w3schools)
I don't know about other people, but along with <<timedinsert>> and <<continue>>, I'd say <<playsound>> is one of my favorite/most used of your macros. Being able to plug macros into links would be AMAZING.
Oh, and Leon, if no one's said it recently... you rock!
Updating my post:
Here is the macro here http://www.glorioustrainwrecks.com/node/5061
I think 1.4 has <<playsound>> built-in.