Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Help making a Mute / Unmute button ? [Harlowe]

$
0
0
Hey again everyone,

slowly but surely becoming less of a noob but at the moment having some trouble with audio in Harlowe (yes, in hindsight I'm aware that it probably wasn't the best format choice for using music but oh well ^^; )

I'd like to have some background music autoplay in loop but also have a button for users to be able to Mute/UnMute the music if they want. Here's an example I made in standard html.

To replicate that in twine though, So far I have this:

In a passage with a header tag:
{
<audio autoplay loop id="longlost" > 
<source src="https://dl.dropboxusercontent.com/u/56322638/twine/long_lost_8bit.mp3&quot;
type="audio/mpeg">
</audio>

<button type ="button" class="button" id="mute"> 
<img id="muteimg" src="https://dl.dropboxusercontent.com/u/56322638/twine/mymutebuttonwh.png&quot; 
alt="mute" onClick="toggleMute(this);">
</button>
}

Then in the javascript:
function toggleMute (img) {
	var image = document.getElementById('muteimg');
	var audio = document.getElementById('nowplaying');

	if (img.src.match ("mymutebuttonwh")) {
		image.src = "https://dl.dropboxusercontent.com/u/56322638/twine/myunmutebuttonwh.png";
		audio.muted = true;
	}else {
		image.src = "https://dl.dropboxusercontent.com/u/56322638/twine/mymutebuttonwh.png";
		audio.muted = false;
	}
}


The music autoplays in loop fine , but on clicking the button I get this error message :
"Sorry to interrupt, but this page's code has got itself in a mess. RefferenceError: toggleMute is not defined at HTMLImageElement.onclick. (This is probably a bug in the Twine game Engine.)"


so I'm pretty sure my code is wrong somewhere but I'm not sure how to fix it.

Thanks for the help !!


Viewing all articles
Browse latest Browse all 1844

Trending Articles