Hopefully this is simple

can someone tell me why step 2 happens twice?

[code]
local step = 1
local function runme(event)
local function step1(event)
step = 2
end

[code]
local function step2(event)
step = 3
end

[code]
if step == 1 then
print(“step 1”)
step = 0
timer.performWithDelay( 1500, step1, 0)
elseif step == 2 then
print(“step 2”)
step = 0
timer.performWithDelay( 2500, step2, 0)
elseif step == 3 then
print(“done!”)
Runtime:removeEventListener(“enterFrame”, runme);
else
–step 0
print(“waiting for step to finish”)
end
end
Runtime:addEventListener(“enterFrame”, runme); [import]uid: 1896 topic_id: 249 reply_id: 300249[/import]

In your calls to ‘timer.performWithDelay()’, an ‘iterations’ count of ‘0’ (zero) means, “Loop Forever”. So your timers are getting in each others way.

The first timer waits for 1500ms, then fires.

The second timer begins to wait for 2500ms.

1500ms later (1000ms before the seconds timer fires) the first timer fires again, mucking everything up (including causing a third timer to be created!)

Solutions:

  1. Use 1 for the ‘iterations’ count (or don’t pass in anything as 1 is the default)
    -OR-
  2. Store the timer-id, and cancel the old timer before starting a new timer.

HTH [import]uid: 1581 topic_id: 249 reply_id: 313[/import]

Of course! I thought it meant repeat 0 times… Thanks man. [import]uid: 1896 topic_id: 249 reply_id: 314[/import]