onComplete Firing Immediately

I have the following code in my program:

1
2
3
4
5
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()} )

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.

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.

views:1755 update:2011/10/1 9:04:19
corona forums © 2003-2011