I am trying to make a script sleep and I am new to this language like 5 minutes new. How do you make it sleep or pause for 10 seconds? I found this
os.execute("sleep " .. tonumber(n))
But how do you define (n)?
Jump to content
I don't know about the code you posted, but it seems os.execute does not work reliable on all devices (depending on your input).
The important question is, what do you want to do. Do you really want to like freeze your app like your code suggests or do you just want to wait some time to execute some code?
If it's the second you should take a look at timers, which call a function after a given delay.
timer.performWithDelay( delay, listener )
Follow this link to the documentation for further information:
I downloaded Corona today and I'm still experimenting it, but to the point:
if I wanted to have a timer count from 3 to 1 yielding a second on each number I'd have to do something like
local textObj = display.newText("",160,0,"Arial",50) local setText = function(obj,t) obj.text = t end for i = 0,3 do timer.performWithDelay(1000*i,function() setText(textObj,3-i) end) end
It feels stupid to define a function for each little thing I need, when I could just do
local textObj = display.newText("",160,0,"Arial",50) for i = 3,1,-1 do textObj.text = i wait(1) -- sleep(1000) end
I've got 4 years with lua on ROBLOX so I'm probably just be used to their system. Also I've got no experience on yielding in other languages (well I just know a bit of PHP) so I don't know how they handle that. I would love to hear from someone if the first piece of code is even the correct way to do it.
local textObj = display.newText("",160,0,"Arial",50) local ticks = 3 local setText = function(obj,t) obj.text = t end timer.performWithDelay( 1000, function() setText(textObj, ticks); ticks = ticks - 1; end, 3)
This method tells the timer to run 3 times, with a 1 second delay.
Community Forum Software by IP.Board