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.
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.