wait() doesn't work

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
SeargeantOfArmy
Prole
Posts: 1
Joined: Fri Sep 17, 2021 7:53 am

wait() doesn't work

Post by SeargeantOfArmy »

guys how to use wait() :oops:
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: wait() doesn't work

Post by BrotSagtMist »

Where did you get that idea that this exists in the first place?
You probably mean: love.timer.sleep( s )
obey
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: wait() doesn't work

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: wait() doesn't work

Post 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.
Me and my stuff :3True 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.
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

Re: wait() doesn't work

Post 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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: wait() doesn't work

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest