Howdy, Stranger!

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

Twine 2, Harlow: Have a sound embedded in a passage—but only want to play it once per game.

edited March 2016 in Help! with 2.0
I'm writing an interactive novella. I'm creating sounds/music in FL Studio. So far, I've gotten audio to work well except for the fact that when a player returns to a given passage, the sound effect/music plays again.

This gets repetitive because some of the sounds are intentionally jarring. Is it possible to set it so that it only plays on first visit?

Example of what I've tried:

(if: (count: (history:), "Bianca") is 0[<audio src="Bianca Singing.mp3" autoplay>]



But it looks like HTML elements don't work with hooks. I get that this code would be redundant, but I figure it would be part of the logic I would use to get it to play only once.

I'm just starting out in programming. That's why I'm using Harlow, I guess. (Well, it looks great right off the bat, too)

Is there a workaround? Or would I use Java for this? (Which I don't know :P)

TY!!

Comments

  • There is a syntax error in your code example, it is missing a ) after the zero.
    (if: (count: (history:), "Bianca") is 0)[<audio src="Bianca Singing.mp3" autoplay>]
    
    ... another way to check History for Bianca is:
    (if: not ((history:) contains "Bianca"))[<audio src="Bianca Singing.mp3" autoplay>]
    

    warning: The array returned by the (history:) macro gets larger each time the Reader navigates from one passage to another. This means that each search for a particular passage name will take slightly longer the more passages a Reader has seen, which could cause a slight delay if the number of passages seen becomes large enough or if your story contains many checks.

    You make want to use variables instead, the following assumes you have set $heardBianca to false at the start of your story.
    (if: not $heardBianca)[<audio src="Bianca Singing.mp3" autoplay>(set: $heardBianca to true)]
    
Sign In or Register to comment.