Why doesnt a timer work inside a function?

Must be missing something obvious here. :wink:

[lua]local function someFunction()
timer.performWithDelay(10000, print(“times up”));
end

someFunction();[/lua]

It just prints times up straight away…

Thanks

Tom [import]uid: 55068 topic_id: 14016 reply_id: 314016[/import]

I don’t think you can call functions like that.

Try:

  
function printIt()  
 print("times up")  
end  
  
function someeFunction()  
 timer.performWithDelay(10000, printIt)  
end  
  
someFunction()  

timer.performWithDelay is looking for a pointer to the function. When you call print(blahlbahblah) you’re actually trying to run the print function.

I’ll test this to make sure. EDIT- Yep, worked.

just to clarify:

“myFunction” and “myFunction()” are different to the compiler. The first is the “address of” the function, the second form with the parens says to execute the function. timer.performWithDeal needs the address.

I’m surprised that it printed at all.

[import]uid: 19626 topic_id: 14016 reply_id: 51634[/import]

try enclosing the function like this

local function someFunction()
timer.performWithDelay(10000, function() print(“times up”) end);
end
 
someFunction();
[import]uid: 43961 topic_id: 14016 reply_id: 51653[/import]

Thanks for the help, both of you. Much appreciated.

Tom [import]uid: 55068 topic_id: 14016 reply_id: 51744[/import]