Howdy, Stranger!

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

stop audio when dialog box is closed

it's me again and with a new problem :) , im using Twine 2.0 with sugarcube 2

my question is, when im using popup box and some of audio is playing but when im closing the popup, the audio is still playing, how to stop it ? is there any event trigger when popup is closing ? i want the audio stop playing when popup is closing.

this is the popup trigger
<<popup "Smartphone" "Phone">></span>

and this is code for "Phone" passage

Insert the phone number<br>

<<textbox "$phoneNum" "123456789">><br><br>

<<button "Call">>
  <<if $phoneNum eq 08199999 or $phoneNum eq 08135762>>
  	<<replace "#phone-wrap">>
  		<<display [[Call]] "div">>
  	<<replace "#phone-wrap">>
    	wrong number

<span id="phone-wrap"></span>


in this case the audio is in "Call" passage, im adding it using display macro

any help will be appreciated, thx before :)


  • Without knowing what code you are using to implement the <<popup>> macro/widget it is hard to say if it has events.

    The two audio macros you can use to stop playing are <<stopallaudio>> or <<audio "track_id" stop>>
  • edited December 2015
    sorry for the lack of information, im using claretta's popup which already fix by TME for sugarcube 2

    the thing is, when i close the popup, the audio is still playing ... how can i stop it when i close the popup ? thx for the quick reply
  • The easiest thing would be to update the macro to take an optional third argument, which would be the name of a passage to silently execute when the dialog is closed.

    Like so: (requires SugarCube 2 ≥ v2.0.0-beta.8)
    	Pops open a dialog.
    	<<popup link_text dialog_passage [closing_passage]>>
    	    link_text       : The text of the link.
    	    dialog_passage  : The name of the passage which will be
    	                      rendered into the dialog.
    	    closing_passage : (optional) The name of the passage
    	                      which will be silently executed when
    	                      the dialog is closed.
    	    <<popup "Journal" "OpenJournal">>
    	    <<popup "Journal" "OpenJournal" "CloseJournal">>
    Macro.add("popup", {
    	handler : function () {
    		if (this.args.length < 2) {
    			var errors = [];
    			if (this.args.length < 1) { errors.push("link text"); }
    			if (this.args.length < 2) { errors.push("dialog passage name"); }
    			return this.error("no " + errors.join(" or ") + " specified");
    		var	dialogPassage = this.args[1],
    			closePassage  = this.args.length > 2 ? this.args[2] : null;
    		if (!Story.has(dialogPassage)) {
    			return this.error('nonexistent dialog passage "' + dialogPassage + '"');
    		if (closePassage !== null && !Story.has(closePassage)) {
    			return this.error('nonexistent closing passage "' + closePassage + '"');
    		var el = document.createElement("a");
    		el.innerHTML = this.args[0];
    		el.className = "link-internal macro-popup";
    		el.setAttribute("data-passage", dialogPassage);
    			this.self.createOpenFn(el.textContent, dialogPassage),
    			closePassage !== null ? this.self.createCloseFn(closePassage) : null
    	createOpenFn : function (title, passage) {
    		return function () {
    			var	dialog = UI.setup(title, "popup");
    			new Wikifier(dialog, Story.get(passage).processText().trim());
    	createCloseFn : function (passage) {
    		return function () {
    			new Wikifier(null, Story.get(passage).processText().trim());

    You'd probably want to use it something like the following:
    <<popup "Smartphone" "Phone" "ClosePhone">>
    And then in your "ClosePhone" passage you would do what greyelf suggested and use either <<audio "track_id" stop>> or, if no other audio was playing, just use <<stopallaudio>>.
  • edited December 2015
    cant speak a word of TME awesomeness
Sign In or Register to comment.