0 Replies - 1010 Views - Last Post: 19 May 2010 - 03:49 PM

#1 athlon32  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 363
  • Joined: 20-August 08

[LUA]Sleep Function

Posted 19 May 2010 - 03:49 PM

Description: Should work fine. Report errors if you have any :DAn easy to use Sleep function that can really come in handy (especially debugging) :)
require "os"

-- get start time, and just keep subtracting it from the current time
-- until it is greater than the time specified. Also note that 'os.clock()'
-- works in seconds not 'ticks' or milliseconds or w/e. This function respects
-- that, and thus time must be specified 'in seconds' (e.g. one second would be
-- '1', not '1000', half a second would be '.5' not '500', and so forth)
function Sleep(length)
    local start = os.clock()
   
    while os.clock() - start < length do end
end

-- just an implementation, ignore if you don't care
print("Ignition in...")
for i = 0,9 do 
	print(10-i .. "...")
	Sleep(1)
end 
print("Blast off!")


Is This A Good Question/Topic? 0
  • +

Page 1 of 1