Page 1 of 1

wait() doesn't work

Posted: Fri Sep 17, 2021 7:55 am
by SeargeantOfArmy
guys how to use wait() :oops:

Re: wait() doesn't work

Posted: Fri Sep 17, 2021 11:51 am
by BrotSagtMist
Where did you get that idea that this exists in the first place?
You probably mean: love.timer.sleep( s )

Re: wait() doesn't work

Posted: Fri Sep 17, 2021 1:07 pm
by MrFariator
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.

Re: wait() doesn't work

Posted: Fri Sep 17, 2021 2:54 pm
by zorg
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.

Re: wait() doesn't work

Posted: Fri Sep 17, 2021 3:38 pm
by darkfrei
SeargeantOfArmy wrote: Fri Sep 17, 2021 7:55 am guys how to use wait() :oops:

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
Or set 3 seconds pause as:

Code: Select all

function love.keypressed(key, scancode, isrepeat)
	if key == "space" then
		waiting = 3
	end
end

Re: wait() doesn't work

Posted: Sat Sep 18, 2021 10:56 am
by pgimeno
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