wait() doesn't work
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Fri Sep 17, 2021 7:53 am
wait() doesn't work
guys how to use wait()
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: wait() doesn't work
Where did you get that idea that this exists in the first place?
You probably mean: love.timer.sleep( s )
You probably mean: love.timer.sleep( s )
obey
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: wait() doesn't work
Alternatively, if you mean the wait command from unix or C, I guess one way to do it is to spawn a thread, let the thread do anything that is needed (system calls or otherwise) and wait for it send a corresponding message back via channels. The love.thread page on the wiki has a simple example.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: wait() doesn't work
also, don't use love.timer.sleep for waiting unless you want to block all processing... and usually that's not what you want.
learn about timers and use those.
learn about timers and use those.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: wait() doesn't work
Code: Select all
function love.update (dt)
if waiting then
waiting = waiting - dt
if waiting < 0 then waiting = nil end
else
-- your update code
-- set "waiting = 3" here to wait 3 seconds to next updating:
if need_wait_3_seconds then
waiting = 3
end
end
end
Code: Select all
function love.keypressed(key, scancode, isrepeat)
if key == "space" then
waiting = 3
end
end
Re: wait() doesn't work
I wonder if you're talking about the function in hump.timer. If that's the case, you need to create a function with the code that must do the wait, and call timer.update from love.update, like this:
Code: Select all
local timer = require 'hump.timer'
local text = nil
local font = love.graphics.setNewFont(40)
timer.script(function (wait)
text = "Hello"
wait(1)
text = "World"
wait(1)
text = nil
end)
function love.update(dt)
timer.update(dt)
end
function love.draw()
if text ~= nil then
love.graphics.print(text)
end
end
Who is online
Users browsing this forum: Google [Bot] and 3 guests