[Resolved] Calling a function within timer.performwithdelay

Hi guys,

I am having trouble with performWithDelay. If I call a function within without passing any variables, then everything is peachy, however whenever I do this:

 timer.performWithDelay(200 , createBricks(0,0) , 10)  

instead of repeating the command 10 times, it just calls it once. Total newbie here, so please bear with me.

Thank you
[import]uid: 99031 topic_id: 30150 reply_id: 330150[/import]

As I remember it, you can’t pass arguements into functions with the timer.performWithDelay… Only createBricks… You can get around this using Lua closures… Basically a small function that calls another function… So it would be like this…

local closure = function() createBricks(0,0) end  
timer.performWithDelay(200 , closure , 10)  

I’m pretty sure this is right… Haven’t used one myself in a bit…

Hope this helps!

-Jake [import]uid: 144504 topic_id: 30150 reply_id: 120724[/import]

I am maybe wrong here but:

  
timer.performWithDelay(200 , {function() createBricks(0,0) end} , 10)  
  

Would maybe work?

Joakim [import]uid: 81188 topic_id: 30150 reply_id: 120726[/import]

haha, that is actually shorter than my solution… I’m a noob… [import]uid: 144504 topic_id: 30150 reply_id: 120727[/import]

Haha, I am a noob as well :wink:

Keep it up!

Joakim [import]uid: 81188 topic_id: 30150 reply_id: 120730[/import]

noob power!

thanks guys :slight_smile: [import]uid: 99031 topic_id: 30150 reply_id: 120733[/import]

@jkrassman Thanks :slight_smile:

@app1 np! [import]uid: 144504 topic_id: 30150 reply_id: 120735[/import]

Actually I think it’s…

timer.performWithDelay(200 , function() createBricks(0,0) end , 10)  

[import]uid: 19626 topic_id: 30150 reply_id: 120738[/import]

Thanks Rob, that works like a charm :slight_smile: [import]uid: 99031 topic_id: 30150 reply_id: 120836[/import]

As I remember it, you can’t pass arguements into functions with the timer.performWithDelay… Only createBricks… You can get around this using Lua closures… Basically a small function that calls another function… So it would be like this…

local closure = function() createBricks(0,0) end  
timer.performWithDelay(200 , closure , 10)  

I’m pretty sure this is right… Haven’t used one myself in a bit…

Hope this helps!

-Jake [import]uid: 144504 topic_id: 30150 reply_id: 120724[/import]

I am maybe wrong here but:

  
timer.performWithDelay(200 , {function() createBricks(0,0) end} , 10)  
  

Would maybe work?

Joakim [import]uid: 81188 topic_id: 30150 reply_id: 120726[/import]

haha, that is actually shorter than my solution… I’m a noob… [import]uid: 144504 topic_id: 30150 reply_id: 120727[/import]

Haha, I am a noob as well :wink:

Keep it up!

Joakim [import]uid: 81188 topic_id: 30150 reply_id: 120730[/import]

noob power!

thanks guys :slight_smile: [import]uid: 99031 topic_id: 30150 reply_id: 120733[/import]

@jkrassman Thanks :slight_smile:

@app1 np! [import]uid: 144504 topic_id: 30150 reply_id: 120735[/import]

Actually I think it’s…

timer.performWithDelay(200 , function() createBricks(0,0) end , 10)  

[import]uid: 19626 topic_id: 30150 reply_id: 120738[/import]

Thanks Rob, that works like a charm :slight_smile: [import]uid: 99031 topic_id: 30150 reply_id: 120836[/import]

recursive call of function or  timer infinity

show/hide two images

To explain behavior:
Timer.performWithDelay just calls function passed as argument. So if your argument was createBrick(0,0) then timer is trying to do something like this: createBrick(0,0)() which doesn’t work because createBrick probably doesn’t return function (yes, function is executed before it is passed as timer argument). You must pass parametless function as argument, but you pass result of calling
createBrick()