onComplete Firing Immediately

I have the following code in my program:

local test = function( obj )  
 print( "done")  
end  
  
transition.to( grid[bS].visual, { time=2000, x=gridX+21+((temp1x-1)\*43) , y= gridY+21+((temp1y-1)\*43), onComplete = test()} )  

Despite all my best efforts and various changes of the time param, the message prints as soon as the transition is reached and not after is it done. Has anyone else experienced this or see anything wrong with my code? I literally copy and pasted from the reference page and just changed the names so I don’t know where the error lies.

Thanks. [import]uid: 8666 topic_id: 9830 reply_id: 309830[/import]

Well I figured out that it was because the onComplete=test() causes the problem. Changing it to test without the parenthesis fixed the issue although I am not exactly sure why that is. [import]uid: 8666 topic_id: 9830 reply_id: 35801[/import]

As per my understanding, lua functions are like variables i.e they can be used like variables e.g. used as parameters for other functions or can be returned as result of some other function.

Now when you say onComplete = test() - lua is assigning result of test() function to onComplete property and hence test() gets executed immediately.

When you say onComplete = test - lua is assigning the function “test” itself to onComplete property and executes it only when you want it to.

[import]uid: 48521 topic_id: 9830 reply_id: 35812[/import]

OK for the advice (also here: http://developer.anscamobile.com/forum/2011/06/18/oncomplete-not-behaving-expected)

So why my onComplete fires immediately with this :

transition.to(graphN, { x = position, time = 1000, easing= linear, onComplete = function() graphN:setText(stringN) end})

I have really no idea … [import]uid: 9328 topic_id: 9830 reply_id: 75100[/import]