Page 1 of 1
Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 4:16 am
by Kookerus
I'm trying to print some text, call 'love.timer.sleep', print some more text, sleep again, print more text etc.
The problem is, instead of sleeping one second and printing the text, it sleeps 3 seconds and then prints all the text at once. How do I fix this?
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 4:33 am
by Kingdaro
Are you using the print() function, or the love.graphics.print() function?
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 5:07 am
by Kookerus
I was using 'love.graphics.print', but after trying just 'print' it works, but prints to the console, which I don't want
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 6:48 am
by micha
Any changes on screen are only shown, when "love.graphics.present()" is called. This is done automatically after each "love.draw()". So if you have multiple print statements in one draw, then all the changes will be done, but not be visible.
I recommend against using love.timer.sleep. Please read
the other thread to a cleaner solution. There is also a
blog-entry about time. Rule of thumb: Only use love.timer.sleep if you really know what you are doing.
Long story short, instead of using sleep, better try it like this:
Code: Select all
function love.load()
timer = 0
end
function love.update(dt)
timer = timer + dt
end
function love.draw()
if timer > 3 then
love.graphics.print('Text after 3 seconds', 100,100)
end
if timer > 6 then
love.graphics.print('Text after 6 seconds', 100,120)
end
end
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 10:53 am
by pielago
This is how i use timer in a way ...
Hope it helps how to print on screen!
Code: Select all
local g=love.graphics
g.setBackgroundColor(100,100,100,255)
local s=0
local time = 05
local white={255,255,255}
local red={255,0,0}
function love.update( dt )
time = time - dt
if time < 0 then
time= 0
s= 1
end
end
function love.draw()
local minutes = math.floor( time / 60 )
local seconds = math.floor( time % 60 )
g.setColor(white)
g.print( string.format("%02d:%02d",minutes,seconds), 400, 300 )
if s==1 then
g.setColor(red)
g.print("Clock Stop", 400, 320 )--print to screen!
end
end
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 7:04 pm
by Jasoco
You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:
Code: Select all
message = {
text = "This is my message",
visible = true
}
local seconds = 2 --a second or two
message.timer = cron.after(seconds, function() message.visible = false end)
function yourDrawingFunction()
if message.visible then
love.graphics.print(message.text, 10, 10)
end
end
Cron 2.0 thread
Re: Need Help With love.timer.sleep
Posted: Wed Jul 30, 2014 7:34 pm
by Kookerus
Jasoco wrote:You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:
Code: Select all
message = {
text = "This is my message",
visible = true
}
local seconds = 2 --a second or two
message.timer = cron.after(seconds, function() message.visible = false end)
function yourDrawingFunction()
if message.visible then
love.graphics.print(message.text, 10, 10)
end
end
Cron 2.0 thread
When I use your code, nothing appears on screen.
Re: Need Help With love.timer.sleep
Posted: Thu Jul 31, 2014 12:08 am
by Jasoco
Kookerus wrote:Jasoco wrote:You seem to have created two threads for the same issue. So I'll repost my same reply here:
Use a Timer library like Cron. Don't use love.timer.sleep or os.execute. They don't do what you think they do.
If you use cron, it would be as easy as:
Code: Select all
message = {
text = "This is my message",
visible = true
}
local seconds = 2 --a second or two
message.timer = cron.after(seconds, function() message.visible = false end)
function yourDrawingFunction()
if message.visible then
love.graphics.print(message.text, 10, 10)
end
end
Cron 2.0 thread
When I use your code, nothing appears on screen.
It's pseudocode. It's an example. Of course it's not drawing anything because you didn't put anything in love.draw().