Delay function isn't working.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Delay function isn't working.

Post by DeadInternal »

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.

Code: Select all

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
Attachments
GunShotPlayer.love
The .love file
(77.27 KiB) Downloaded 340 times
- Active guitarist
- Active programmer
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Delay function isn't working.

Post by bartbes »

What the-

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.
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Re: Delay function isn't working.

Post by DeadInternal »

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.
- Active guitarist
- Active programmer
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Delay function isn't working.

Post by kikito »

Maybe you want to give a look at cron.lua. cron.after might be what you are looking for.
When I write def I mean function.
User avatar
DeadInternal
Prole
Posts: 9
Joined: Fri May 25, 2012 1:53 am

Re: Delay function isn't working.

Post by DeadInternal »

kikito wrote:Maybe you want to give a look at cron.lua. cron.after might be what you are looking for.

That solved it! Thank you!
- Active guitarist
- Active programmer
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests