Is there such thing as a wait() function?

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
Are31
Prole
Posts: 2
Joined: Sat Jun 02, 2012 2:21 am

Is there such thing as a wait() function?

Post by Are31 »

I have just joined, so I do not know if this is in the right area of the Forums. Sorry.

I have played a few other games where they have wait() functions and I was wondering if there was anything like that here.
I am trying to make a character jump when you hit the up arrow but I don't have a wait function, so I can't seem to work it.
User avatar
litearc
Citizen
Posts: 57
Joined: Thu May 17, 2012 12:40 am

Re: Is there such thing as a wait() function?

Post by litearc »

A quick search for "lua sleep function" gives (from http://lua-users.org/wiki/SleepFunction):

Code: Select all

local clock = os.clock
function sleep(n)  -- seconds
  local t0 = clock()
  while clock() - t0 <= n do end
end
-- warning: clock can eventually wrap around for sufficiently large n
-- (whose value is platform dependent).  Even for n == 1, clock() - t0
-- might become negative on the second that clock wraps.
Note that this is a blocking function, meaning while you're waiting, you cannot do anything else - essentially, you're freezing the game for a while. If you want a non-blocking function, you need to integrate your code with the while loop somehow.
Are31
Prole
Posts: 2
Joined: Sat Jun 02, 2012 2:21 am

Re: Is there such thing as a wait() function?

Post by Are31 »

Somebody needs to tell the developers to add a wait() function....
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Is there such thing as a wait() function?

Post by Inny »

There was a thread about this just last week: viewtopic.php?f=4&t=9345
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Is there such thing as a wait() function?

Post by bartbes »

@litearc: That's absolutely terrible. It's a busy loop, they are bad. At least mention love.timer.sleep.

But, as linked before, you don't want to pause execution.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests