Starting a timer that is in another scene?

Hey all :slight_smile: I’m trying to get my head around this one.

I am using director and have two scenes setup. One lets people input some data, and the other screen is a counter. Both are working perfectly.

What i am trying to do, is when the user has finished entering the data on the first scene and click a button. I want the timer on the second scene to start right away.

At the moment it only starts when a user enters scene 2, and when they leave it resets.

I tried adding

myTimer = timer.performWithDelay(1, \_G.PrintIt, 0)  

to the button in the first scene, but this just made the timer stop showing.

Am i on the right track with this, or completely wrong? Thank you for any advice [import]uid: 120612 topic_id: 26994 reply_id: 326994[/import]

I would go more for an external module with something like this:

--external.lua  
  
local external = {}  
  
--The function you wish to execute (declare it here)  
function external:printIt()  
 print("hello")  
end  
  
return external  

Then in the file with your touch handler

(Note: the function it is trying to execute should be accessible)

--at the top of the file  
local external = require("external")  
  
--Create a handle for the timer  
local tmr  
  
--in your button handler  
if event.phase == "began" then  
 tmr = timer.performWithDelay(1000, external.printIt, 0)  
end  
  
return true  

This is all 100% untested code but it is one way you could handle it
[import]uid: 84637 topic_id: 26994 reply_id: 109508[/import]