Basically what the function is suppose to do is wait the amount of seconds specified. The function is inside the love.update function. This is the first block of code. The second block of code basically plays 2 noises if you click the left mouse button. First it plays the 'fire' noise, then after 5 seconds it's suppose to play the 'shell' noise. However, no time is waited at all and they're both played at the same time.
function love.update(dt)
function wait(time)
local total = 0
repeat total = total + dt
until total >= time
end
end
function love.mousepressed(mousex, mousey, button)
if button == "l" then
fire = love.audio.newSource("src/sound/pistolfire.mp3", "static")
love.audio.play(fire)
wait(5)
--Shell dropping sound--
shell = love.audio.newSource("src/sound/pistolshell.mp3", "static")
love.audio.play(shell)
end
end
First, don't define functions inside other functions, you can, but you don't look like you know what you're doing with it.
Another thing to note, you'll never be able to build a 'synchronous' wait that doesn't completely block all other games, so you won't ever be able to use something like that inline.
So is it flat-out not logically possible to create a wait? I was thinking about attempting a few experiment with coroutines next. Bleh, I'll live without the wait.