{{newin|[[0.2.1]]|021|type=function}}
Pauses the current thread for the specified amount of time.
{{notice|This function causes the entire thread to pause for the duration of the sleep. Graphics will not draw, input events will not trigger, code will not run, and the window will be unresponsive if you use this as "wait()" in the main thread. Use [[love.update]] or a [[love.timer|Timer library]] for that instead.}}
== Function ==
{{newin|[[0.8.0]]|080|type=behaviour}}
=== Synopsis ===
<source lang="lua">
love.timer.sleep( s )
</source>
=== Arguments ===
{{param|number|s|Seconds to sleep for.}}
=== Returns ===
Nothing.
== Function ==
{{oldin|[[0.8.0]]|080|type=behaviour}}
=== Synopsis ===
<source lang="lua">
love.timer.sleep( ms )
</source>
=== Arguments ===
{{param|number|ms|Milliseconds to sleep for.}}
=== Returns ===
Nothing.
== Examples ==
=== Use sleep to cap FPS at 30 ===
<source lang="lua">
function love.update(dt)
   if dt < 1/30 then
      love.timer.sleep(1/30 - dt)
   end
end
</source>
=== More sophisticated way to cap 30 FPS ===
This takes into account the time spent updating and drawing each frame.
<source lang="lua">
function love.load()
   min_dt = 1/30
   next_time = love.timer.getTime()
end

function love.update(dt)
   next_time = next_time + min_dt

   --rest of function here
end

function love.draw()
   --rest of function here

   local cur_time = love.timer.getTime()
   if next_time <= cur_time then
      next_time = cur_time
      return
   end
   love.timer.sleep(next_time - cur_time)
end
</source>

== See Also ==
* [[parent::love.timer]]
[[Category:Functions]]
{{#set:Description=Pauses the current thread for the specified amount of time.}}
{{#set:Since=021}}
{{#set:PrettySince=0.2.1}}

== Other Languages ==
{{i18n|love.timer.sleep}}