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.
Pauses (Waits, sleeps, etc.), is it Possible?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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?
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?
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
Re: Pauses (Waits, sleeps, etc.), is it Possible?
It was an exampleWhy would you write such a function?
Re: Pauses (Waits, sleeps, etc.), is it Possible?
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).nate890 wrote: No error there, still crashes.
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
Re: Pauses (Waits, sleeps, etc.), is it Possible?
"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.
Actually seems to reach 300+FPS on occasion.
- 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?
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.nate890 wrote:Actually seems to reach 300+FPS on occasion.
Help us help you: attach a .love.
- slime
- Solid Snayke
- Posts: 3160
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Pauses (Waits, sleeps, etc.), is it Possible?
.... what?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.
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.
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Pauses (Waits, sleeps, etc.), is it Possible?
But that's a paradox. It could destroy the whole universe! Great Scott!Robin wrote: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.nate890 wrote:Actually seems to reach 300+FPS on occasion.
Who is online
Users browsing this forum: No registered users and 0 guests