Howdy, Stranger!

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

The command to loop music in SugarCube Twine 2

edited September 2015 in Help! with 2.0
I tried to find it, and I know Greyelf or The Mad Exile will probably know this instantly even though I have spent half an hour looking lol On my game I am using:

<<cacheaudio "main_theme" "Music/Theme.mp3">>

and then:

<<audio "main_theme" play>>

And it has worked perfectly! I know zilch programming, and when I looked for how to loops sounds I saw elaborate macros. but, is there just an easy way to loop something? Like:

<<audio "main_theme" loop>>

and then I can use the

<<audio "main_theme" stop>>

Later to end it, I am sure. Isn't there just something easy like that?

Comments

  • edited September 2015
    You need to use the playlist macro which is a separate music "track".

    Example from my story:

    In StoryInit:
    <<cacheaudio "music1" "sound/music1.ogg">>
    <<cacheaudio "music2" "sound/music2.ogg">>
    <<cacheaudio "music3" "sound/music3.ogg">>
    <<setplaylist "music3" "music1" "music2">>
    


    Where you want music to start looping:

    <<playlist play>>


    Be aware that looping in html5 audio is not perfect, so design your tracks to take into account this (i.e. they should sound natural with a small silence at the end of each track, so is good to have fadeouts and fadeins at the start and end.)


    See the SugarCube audio docs for more info on the playlist macro.
  • edited September 2015
    That is an idea, and then that makes me wonder two things, one, should I then use,

    <<playlist stop>>

    to end it? And two, what if I have multiple playlists then? Would:

    <<cacheaudio "music1" "sound/music1.ogg">>
    <<cacheaudio "music2" "sound/music2.ogg">>
    <<cacheaudio "music3" "sound/music3.ogg">>
    <<cacheaudio "music4" "sound/music4.ogg">>
    <<cacheaudio "music5" "sound/music5.ogg">>
    <<cacheaudio "music6" "sound/music6.ogg">>
    <<setplaylist "music3" "music1" "music2">>
    <<setplaylist 2 "music4" "music5" "music6">>

    work?

    Then do:

    <<playlist play>>
    <<playlist stop>>
    <<playlist 2 play>>

    So strange one cannot just say loopsound or something lol
  • edited September 2015
    You can loop sound.

    <<audio "track1" loop play>>

    It's all there in the manual - look a bit closer at the audio macros.


    However, regarding your playlist question, you cannot set different playlists, but you can update them dynamically.

    So if in storyinit you start out with:

    <<setplaylist "music3" "music1" "music2">>

    Then in a passage you might write to change it:

    <<setplaylist "music4" "music5" "music6">>



    The main reason I recommend playlist instead of audio for music is it gives you a lot more control. With audio you're pretty much limited to looping the one track over and over and over. Playlist is called playlist because it's exactly that.


  • I found the solution!!!!!

    Anyone wondering how to do this, I just kept trying different patterns of the word loop in the thing (I have no idea what these things are called) but I put this in the thing and it works!

    <<audio "main_theme" loop play>>
  • Oh crap you beat me to it by about 10 seconds
  • Also, I didn't buy a box set of SugarCube, so I don't have a manual. I just have basically thrown crap at it and seen what has stuck. Sorry that I had to use these forums, but Google was no help! Thanks though for your help!
  • I mean the online manual, the link I pasted. If you're looking for information on any macro, that's the place to start. :)
  • OH yeah, I see. Thanks! I'm too old for this, but having a blast making an interactive story!
  • edited September 2015
    For your original question. There are many actions you can apply to a track and/or the playlist (see: <<audio>> & <<playlist>> for examples; links are to SugarCube v1.x docs), most of them do not change the playback state. The loop action is one that does not. For example:
    → Start repeating playback of a single track
    <<audio "main_theme" loop play>>
    
    → Flag a track to repeat, but do not alter its current playback state (i.e. start or stop it)
    <<audio "main_theme" loop>>
    

    You stop a track or the playlist via the stop action. For example:
    → Stop playback of a single track
    <<audio "main_theme" stop>>
    
    → Stop playback of the playlist
    <<playlist stop>>
    
    As a special case, since you can have multiple audio tracks all playing simultaneously, there is also the <<stopallaudio>> macro (n.b. does not affect the playlist).

    You are limited to a single playlist at a time. This shouldn't be much of an issue, however, as you can easily swap between multiple playlists via the use of <<widget>>. For example: (goes in a widget tagged passage)
    <<widget "playlist1">><<setplaylist "music3" "music1" "music2">><</widget>>
    <<widget "playlist2">><<setplaylist "music4" "music5" "music6">><</widget>>
    
    Then to use the widgets:
    → Sets the playlist to the tracks: "music3" "music1" "music2"
    <<playlist1>>
    
    → Sets the playlist to the tracks: "music4" "music5" "music6"
    <<playlist2>>
    
    After either of those you may use <<playlist>> normally to control playback of the current playlist.
  • As a special case, since you can have multiple audio tracks all playing simultaneously, there is also the <<stopallaudio>> macro (n.b. does not affect the playlist).

    This is in my PassageReady passage to give people an easy option to stop voice actors speaking, and to ensure they don't speak over the top of each other. It's very handy.
Sign In or Register to comment.