In an easy version of this, there used to be something used to delay: wait()-- number of seconds here
How would I do it in this?
It says nil when I try
Delay on a loop?
Re: Delay on a loop?
Thanks for anyone willing, I hope this is not complicated
Re: Delay on a loop?
I have found this:
... so that a thread can block for a specified amount of time. In love.run, waiting is needed before running the main loop again. Threads can call wait ... M = {} local timers = {} local callbacks = {} function M.start(name, delay, callback) timers[name] = delay callbacks[name] = callback end function ...
by Inny
on Fri Oct 12, 2012 10:32 pm
Forum: Support and Development
Topic: Does love have a 'wait()'?
Replies: 5
Views: 315
Can someone give me a more thorough explanation?
I really have no idea what this is saying.
I started love.lua yesterday and I am quite new
... so that a thread can block for a specified amount of time. In love.run, waiting is needed before running the main loop again. Threads can call wait ... M = {} local timers = {} local callbacks = {} function M.start(name, delay, callback) timers[name] = delay callbacks[name] = callback end function ...
by Inny
on Fri Oct 12, 2012 10:32 pm
Forum: Support and Development
Topic: Does love have a 'wait()'?
Replies: 5
Views: 315
Can someone give me a more thorough explanation?
I really have no idea what this is saying.
I started love.lua yesterday and I am quite new
Re: Delay on a loop?
Hi and welcome to our forum.
In the future, please be a bit more patient and wait for an answer a little longer before you post again. You cannot expect us to respond within half an hour. Also, please avoid double posting (you can edit your entries, if you forgot a line).
Now for your question:
If you want to have a delay, then you should not use a wait function. It would stop the whole program and make it unresponsive. Instead, use a timer and dt to measure time. This could be implemented like this:
To begin the delay do this:
and in the loop that you want to delay you do this:
In the future, please be a bit more patient and wait for an answer a little longer before you post again. You cannot expect us to respond within half an hour. Also, please avoid double posting (you can edit your entries, if you forgot a line).
Now for your question:
If you want to have a delay, then you should not use a wait function. It would stop the whole program and make it unresponsive. Instead, use a timer and dt to measure time. This could be implemented like this:
To begin the delay do this:
Code: Select all
status = 'stopped'
timer = 1
Code: Select all
if status == 'stopped' then
timer = timer - dt
if timer < 0 then
status = 'running'
end
else
-- your normal loop code
end
Check out my blog on gamedev
Re: Delay on a loop?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Delay on a loop?
Thank you, I have made my script, but now it has an error when I try to run it:
function attack2(dt)
divident = 10
timer = 0
repeat timer = timer + dt/dividend until timer == 0.1
if timer == 0.1 then
timer = 0
Bullet = love.graphics.draw(bullet,xpos,ypos - less)
Bullet = nil
end
timer2 = 0
repeat timer2 = timer2 + dt/dividend until timer == 0.1
if timer2 == 0.1 then
timer = 0
EXP1 = love.graphics.draw(exp1,xpos,ypos - less)
timer2 = 0
end
timer3 = 0
repeat timer3 = timer3 + dt/dividend until timer3 == 0.1
if timer3 == 0.1 then
timer3 = 0
EXP2 = love.graphics.draw(exp2,xpos,ypos - less)
end
timer4 = 0
repeat timer4 = timer4 + dt/dividend until timer4 == 0.1
if timer4 == 0.1 then
timer4 = 0
EXP3 = love.graphics.draw(exp3,xpos,ypos - less)
end
repeat timer5 = timer5 + dt/dividend until timer5 == 0.1
if timer5 == 0.1 then
timer5 = 0
EXP1 = nil
end
timer6 = 0
repeat timer6 = timer6 + dt/dividend until timer6 == 0.1
if timer6 == 0.1 then
timer6 = 0
EXP2 = nil
end
timer7 = 0
repeat timer7 = timer7 + dt/dividend until timer7 == 0.1
if timer7 == 0.1 then
timer7 = 0
EXP3 = nil
end
end
Error says: attempt to perform arithmetic on local 'dt' ( a nil value')
All of your help is appreciated!
Just remember, I am new, so please, pardon my errors
function attack2(dt)
divident = 10
timer = 0
repeat timer = timer + dt/dividend until timer == 0.1
if timer == 0.1 then
timer = 0
Bullet = love.graphics.draw(bullet,xpos,ypos - less)
Bullet = nil
end
timer2 = 0
repeat timer2 = timer2 + dt/dividend until timer == 0.1
if timer2 == 0.1 then
timer = 0
EXP1 = love.graphics.draw(exp1,xpos,ypos - less)
timer2 = 0
end
timer3 = 0
repeat timer3 = timer3 + dt/dividend until timer3 == 0.1
if timer3 == 0.1 then
timer3 = 0
EXP2 = love.graphics.draw(exp2,xpos,ypos - less)
end
timer4 = 0
repeat timer4 = timer4 + dt/dividend until timer4 == 0.1
if timer4 == 0.1 then
timer4 = 0
EXP3 = love.graphics.draw(exp3,xpos,ypos - less)
end
repeat timer5 = timer5 + dt/dividend until timer5 == 0.1
if timer5 == 0.1 then
timer5 = 0
EXP1 = nil
end
timer6 = 0
repeat timer6 = timer6 + dt/dividend until timer6 == 0.1
if timer6 == 0.1 then
timer6 = 0
EXP2 = nil
end
timer7 = 0
repeat timer7 = timer7 + dt/dividend until timer7 == 0.1
if timer7 == 0.1 then
timer7 = 0
EXP3 = nil
end
end
Error says: attempt to perform arithmetic on local 'dt' ( a nil value')
All of your help is appreciated!
Just remember, I am new, so please, pardon my errors
Re: Delay on a loop?
Can we see where and how you call attack2? You should call it inside love.update, passing dt to it as argument:
Also, please use the
Code: Select all
function love.update(dt)
---you can have other things in here too
attack2(dt)
end
Code: Select all
tags and indent your code, otherwise it's really difficult to read.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Delay on a loop?
Your code, though
will not make a delay.
This repeat-loop will just add up some numbers in a split second and you will not notice a delay.
You have misunderstood the concept of making a delay. To make a delay, you should NOT try to change the time it takes to do one game-loop (update + draw), but instead you should keep the game loop running and in each iteration do nothing and then after the time is over, do the next action.
Code: Select all
timer = 0
repeat timer = timer + dt/dividend until timer == 0.1
if timer == 0.1 then
timer = 0
This repeat-loop will just add up some numbers in a split second and you will not notice a delay.
You have misunderstood the concept of making a delay. To make a delay, you should NOT try to change the time it takes to do one game-loop (update + draw), but instead you should keep the game loop running and in each iteration do nothing and then after the time is over, do the next action.
Check out my blog on gamedev
Re: Delay on a loop?
Can you give an example of that, or remake my code that way?
I am quite confused.
I am quite confused.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests