Can I define specific points within an audio track (eg seconds elapsed) as a variable? My aim is to try and create an
if command that triggers a 2nd audio track, but is timed to specific places in the first track—so both tracks are in-time musically when they play together (eg “if Track1 is at 2, 4, 6, or 8 seconds, play Track2”).
Many Thanks, Ben
PS… I posted a similar question, but with more detail, here.
I don’t know if a thing exists in Twine. I work in AXMA which has separate macros for background music and macros to repeat a passage at specific intervals. I have kludged around it where I start a music track and know exactly how long I want it to play for, thus setting a repeat macro at that exact number of second-intervals to interrupt the music and do something else. It mostly works, occasionally only goofing up when a music track hasn’t fully loaded and starts a bit late.
I could see it working if there are similar structures in Twine where the repeat passage occurs say every second, and also keeps track of how many times it’s run, thus keeping track of how many seconds the track is in. When the repeat macro fires during the music it can check whether another variable is set or not, and when conditions are met and the second-counting variable detects it is at or after an appropriate place in the music then there’s code to change the music or cue another event.
Re-reading your question, I know there isn’t a method in AXMA to play two simultaneous music tracks together overlapping. In that case, I’d create separate tracks, one with one piece of music, and one with the second overlaid on it with the correct timing, and just switch to the double track to give the impression the music has added another “layer”. This requires some trial and error with the timing, but I have done it before where I’ve built up five layers of music (which are actually five separate tracks each including a new instrument layer.)
You could do something similar to what you want using
setTimeout(). Here’s some reference material on it.
But basically it’d be like
/* change the music */
The callback function will automatically execute after two seconds (2000 milliseconds). I’m using
<<script>> because (if I remember correctly) the
<<set>> macros don’t like the defining of function callbacks, or multiple lines, or something like that. I forget.
But anyway, something like that will work, but I doubt it’d be accurate enough to prevent the music from hiccuping.