Howdy, Stranger!

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

Cutting music playback on load game

edited March 2015 in Help! with 2.0
I just came across an interesting music issue with SugarCube's load game function. If music is playing, and I decide to load game, the music will keep playing as it will reload all variables but not give any stopsound commands. But sometimes the music playing at the start of the game or where ever loaded from will not be appropriate, since I use a specific music track for the start screen.

So is there a way to tie a <<stopallsound>> command to the load game function? Cause I don't want to have to manually append <<stopsound "sound/intromusic.ogg">> to every single passge a player may load to. Or failing that, is there a way to append that command to every single passage except those tagged with a certain identifier? Pretty sure I did this at one point, but have forgotten how I did it.

E.g. Some kind of function that will automatically carry out <<stopsound "sound/intromusic.ogg">> to every passage loaded except for those passages I tag with "intro". Seems kinda excessive to just meet the load game issue, but it'd work.

Comments

  • Two possible ways to achieve what you want are:

    1. The config object's config.saves.onLoad function:
    This allows you to run javascript code when a saved game is loaded.

    config.saves.onLoad = function (save) {
    /* javascript code to stop the music. */
    };
    2. Either one of the PassageReady / PassageDone special passage or one of the predisplay / prerender / postrender postdisplay ]Task Object functions:
    These allow you to run code (either <<macro>> or javascript) every time any passage is shown. You can conditionally test which passage is being shown (via title or tags) so your code only happens when you want it to.
  • Thanks again! Such simple solutions, just am not aware of them.

    Do you have any examples of specific javascript or conditional testing via tags for either options? Bear in mind I say this before I go to look it up myself, so I might end up figuring it out anyway.
  • Ok what I did was put this in PassageDone:

    <<if $time gte 1>><<stopsound "sound/intromusic.ogg">><</if>>
    $time is advanced to 1 once you get past the intro, so it appears to work.
  • You could do it via the onLoad() callback:

    config.saves.onLoad = function () {
    new Wikifier(null, "<<stopallsound>>");
    };

    Or, depending on how you have everything setup, you could put a call to &lt;&lt;stopallsound&gt;&gt; (or &lt;&lt;stopsound &gt;&gt;) in StoryInit special passage (though, that would also stop the audio if the player reloads the page, so maybe not the best solution).
  • TheMadExile wrote:

    you could put a call to &lt;&lt;stopallsound&gt;&gt; (or &lt;&lt;stopsound &gt;&gt;) in StoryInit special passage (though, that would also stop the audio if the player reloads the page, so maybe not the best solution).


    That could actually be doable, thanks. I mean, my current one works fine now, but it would be better to have something that only takes effect on load.
Sign In or Register to comment.