So using Tier1, I'm wanting to queue the playback of sound files; they get thrown into a queue, and one finishes playing, the next one in the queue starts to play. Once all of the sounds are done playing, the queue gets purged and then starts over once new sounds are added.
This would be really easy to do if I kept it in a private for/each loop, but I also need to perform other tasks, like increasing a background timer. So there goes loops.
I have some code jotted down below as pseudo-code. Anyone have any suggestions or might know how to tackle this?
type TYPE_QUEUESOUND
//id of the sound file
soundID as integer
//whether or not sound finished playing
soundFinished as integer
//whether or not sound started playing
soundStarted as integer
//whether or not we can increase background timer
soundPauseTimer as integer
endtype
//counting variable
global queueSoundCount as integer
queueSoundCount = 0
//variable to store the current active index
global queueActiveIndex as integer
queueActiveIndex = -1
//array variable
global dim queueSounds[] as TYPE_QUEUESOUND
//function to add sound to queue
function AddSoundQueue(pID, pPauseTimer)
endfunction
//function to clear the queue and reset values to initial values
function ClearSoundQueue()
endfunction
//function to process sound queue
function UpdateSoundQueue()
//update only if the sound count is greater than zero
//and that active index does not match soundCount
if queueSoundCount > 0 and ((queueActiveIndex = queueSoundCount) = 0)
//get the ball started if the active index is -1 or sound has finished playing
if queueActiveIndex = -1 or queueSounds[queueActiveIndex].soundFinished = 1
queueActiveIndex = queueActiveIndex + 1
endif
//play sound if not playing
if queueSounds[queueActiveIndex].soundStarted = 0
queueSounds[queueActiveIndex].soundStarted = 1
PlaySound(queueSounds[queueActiveIndex].soundID)
endif
//timer gets incremented in another function
pauseTimer = queueSounds[queueActiveIndex].soundPauseTimer
//see if sound is finished
if queueSounds[queueActiveIndex].soundStarted = 1
if GetSoundInstances(queueSounds[queueActiveIndex].soundID) = 0
queueSounds[queueActiveIndex].soundFinished = 1
endif
endif
elseif queueActiveIndex = queueSoundCount
//erase array and reset to zero
ClearSoundQueue()
endif
endfunction
Hi there. My name is Dug. I have just met you, and I love you.