Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

playsound on click?

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 playsound macro isn't mine but I do know some HTML5. You're going to need to modify that javascript for the most straightforward solution.
    var swordnoise = new Audio('URL OF SOUND HERE');
    <map id="buttonmap" name="buttonmap">

    <area shape="rect" coords="0,0,100,100" "href="#" onclick="javascript:state.display('PART_ONE', this);swordnoise.play();return false;"/>
    Be advised that I'm not sure if this will work since I don't have time to test it, only because I'm not sure how much HTML5 vanilla headers support.
  • Liyamu wrote:

    On a previous story, I needed to make a .gif into a link.  I eventually found a solution using (someone else's) javascript:

    The actual solution is to do this:

    [img[name of image][passage name]]
    Assuming you're using built-in images.
    Liyamu wrote:

    I wish we could just put macros inside links... [[Draw your sword|previous()][<<playsound 'sword_draw.mp3'>>]] would be amazing.  Alas...

    One way you can accomplish this is to use a <<replace>> containing both <<playsound>> and <<goto>>:

    <<replace "Draw your sword">><<playsound 'sword_draw.mp3'>><<goto previous()>><<endreplace>>
    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.
  • +1 for that idea  :)
  • L wrote:

    Liyamu wrote:

    On a previous story, I needed to make a .gif into a link.  I eventually found a solution using (someone else's) javascript:

    The actual solution is to do this:

    [img[name of image][passage name]]
    Assuming you're using built-in images.
    Liyamu wrote:
    I wish we could just put macros inside links... [[Draw your sword|previous()][<<playsound 'sword_draw.mp3'>>]] would be amazing.  Alas...

    One way you can accomplish this is to use a <<replace>> containing both <<playsound>> and <<goto>>:

    <<replace "Draw your sword">><<playsound 'sword_draw.mp3'>><<goto previous()>><<endreplace>>
    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!
  • Is this <<playsound 'filename'>> macro working? I have L's custom macros installed and working in my game, but unless there is an update for it that I missed Twine doesn't recognise this macro.

    Updating my post:

    Here is the macro here http://www.glorioustrainwrecks.com/node/5061

  • Dazakiwi38 wrote:

    Is this <<playsound 'filename'>> macro working? I have L's custom macros installed and working in my game, but unless there is an update for it that I missed Twine doesn't recognise this macro.

    Updating my post:

    Here is the macro here http://www.glorioustrainwrecks.com/node/5061


    I think 1.4 has <<playsound>> built-in. 
Sign In or Register to comment.