Timer/wait?

I’ve been looking around but can’t find a way to add a sleep or wait function.

Say I want to wait 1000ms before a function is called- how would I do that?

Thanks a ton to anyone who can help! [import]uid: 66386 topic_id: 14108 reply_id: 314108[/import]

Would you mind posting some code for a reference?

Basically… you need to create a function, then you can use this code
[lua]timer.performWithDelay( 1000, functionNameHere, 1 )[/lua]

the 1000 is the amount of time. 1000 = 1 seconds.

the second 1 is how many times you want the function to run, you don’t need to put it there generally.

cheers! [import]uid: 25216 topic_id: 14108 reply_id: 51949[/import]

Thanks for that- I’ll be sure to save it for future reference. I’m actually not going to have to use that though because I’ve changed the way my program functions.

This is a simple multi-color strobe, but I’m having performance issues. It starts off fast, but overtime slows to ~1 FPS. I guessed that it kept drawing rectangles over each other to the point where there were thousands, and I thought I had fixed that through doing object:removeSelf() but it doesn’t seem to work. If anyone could tell me what I’m doing wrong that would be very helpful- thanks!

[code]
_W = display.contentWidth
_H = display.contentHeight

strobeTime = 5

local function pinkLight()
local pink = display.newRect( 0, 0, _W, _H )
pink:setFillColor(255, 105, 180)
transition.to( pink, { time=strobeTime, onComplete = redLight} )
yellowLight:removeSelf()
end

local function yellowLight()
local yellow = display.newRect( 0, 0, _W, _H )
yellow:setFillColor(255, 255, 0)
transition.to( yellow, { time=strobeTime, onComplete = pinkLight} )
whiteLight:removeSelf()
end

local function whiteLight()
local white = display.newRect( 0, 0, _W, _H )
white:setFillColor(255, 255, 255)
transition.to( white, { time=strobeTime, onComplete = yellowLight} )
blueLight:removeSelf()
end

local function blueLight()
local blue = display.newRect( 0, 0, _W, _H )
blue:setFillColor(0, 0, 255)
transition.to( blue, { time=strobeTime, onComplete = whiteLight} )
greenLight:removeSelf()
end

local function greenLight()
local green = display.newRect( 0, 0, _W, _H )
green:setFillColor(0, 255, 0)
transition.to( green, { time=strobeTime, onComplete = blueLight} )
redLight:removeSelf()
end

function redLight()
local red = display.newRect( 0, 0, _W, _H )
red:setFillColor(255, 0, 0)
transition.to( red, { time=strobeTime, onComplete = greenLight} )
pinkLight:removeSelf()
end

pinkLight()
[/code] [import]uid: 66386 topic_id: 14108 reply_id: 51996[/import]

Shameless self bump. [import]uid: 66386 topic_id: 14108 reply_id: 52229[/import]

remove objects, not a functions, pink:removeSelf() , but this is a waste too, just create them all at the start and play with the alpha= in transition to. 1 is visible 0 is not. [import]uid: 19176 topic_id: 14108 reply_id: 52234[/import]

Ah, that’s a great idea, I’ll try that now. Thanks! [import]uid: 66386 topic_id: 14108 reply_id: 52235[/import]