Pauses (Waits, sleeps, etc.), is it Possible?

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.
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

local x=5

local keys={
["w"]=function()
while true do
x=x+1
love.timer.sleep(10)
end
end;
}

keys["w"]()
No error there, still crashes.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by tentus »

OK, lets figure out whats happening.

First, we define variables x and keys. x is the number 5, keys is a table. Inside of keys we create a function called w. The function w runs an infinite loop that adds 1 to x and the sleeps for ten milliseconds before doing it again. We know that it is an infinite loop because true will always be true.

Why would you write such a function?
Kurosuke needs beta testers
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

Why would you write such a function?
It was an example
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by miko »

nate890 wrote: No error there, still crashes.
It does not crash for me. It just show a black screen and nothing else works (even closing a window by pressing "X" in the corner), which is expected (I hope you expected it also).
BTW, love engine is designed to run each draw/update function 60 times per second (or so), and if you force any of this function to last longer than 1/60 sec then your game has serious problem. If (as in this case) you force it to run indefinitely long, then it has no chance to work correctly. You are just pausing execution of entire system.
In other words: love functions are callbacks, and the love engine controls the main loop. You cannot hijack the main loop, because then love2d engine stops working.
Last edited by miko on Fri Jan 27, 2012 12:32 pm, edited 1 time in total.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
nate890
Prole
Posts: 25
Joined: Tue Jan 24, 2012 10:50 pm

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by nate890 »

"BTW, love engine is designed to run each draw/update function 60 times per second (or so), and if you force any of this function to last longer than 1/60 sec then your game has serious problem."

Actually seems to reach 300+FPS on occasion.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by Robin »

nate890 wrote:Actually seems to reach 300+FPS on occasion.
Until you call that function, right? When you enter that infinite loop, you will get a neverending frame. Unless and until you force-quit LÖVE, you will stay stuck on that frame, even past the end of time.
Help us help you: attach a .love.
User avatar
slime
Solid Snayke
Posts: 3144
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by slime »

miko wrote:BTW, love engine is designed to run each draw/update function 60 times per second (or so), and if you force any of this function to last longer than 1/60 sec then your game has serious problem. If (as in this case) you force it to run indefinitely long, then it has no chance to work correctly. You are just pausing execution of entire system.
In other words: love functions are callbacks, and the love engine controls the main loop. You cannot hijack the main loop, because then love2d engine stops working.
.... what?

The LÖVE framework is not designed for a specific framerate, although it does enable vsync by default. Ideally you'd want your framerate to be consistently at or above the refresh rate of a standard monitor, which happens to be 60hz/fps, but that's standard to all games. You do not ever want to pause execution of the main loop for any noticeable amount of time, if it can be avoided.

LÖVE includes a premade main loop, but you are free to make your own. See love.run.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Pauses (Waits, sleeps, etc.), is it Possible?

Post by Jasoco »

Robin wrote:
nate890 wrote:Actually seems to reach 300+FPS on occasion.
Until you call that function, right? When you enter that infinite loop, you will get a neverending frame. Unless and until you force-quit LÖVE, you will stay stuck on that frame, even past the end of time.
But that's a paradox. It could destroy the whole universe! Great Scott!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests