Yes, that’s a totally valid way (an anonymous function like @roaminggamer suggests). However, sometimes it’s not practical to write a separate embedded function for every transition in your game… you may need to call a common “onComplete” function from many transitions, passing different variables to it each time.
In that case, you could set a temporary table of variables as a property on the object itself, then retrieve those variables in the “onComplete” listener function:
[lua]
local function onc( obj )
local vars = obj.vars
print( vars[1], vars[2], vars[3] )
obj.vars = nil – Clear these variables
end
local player = display.newRect( 0,0,10,10 )
– Set a temporary table of variables as property of player object
player.vars = { “a”, “b”, 3 }
– Transition the player
transition.to( player, { x = 160, y = 160 , time = 5000, onComplete = onc } )
[/lua]
As you can see, the “onComplete” listener function receives a reference to the object that was transitioned (player) as its sole argument, so you can grab the table of variables from that and use them as needed. Then you can clear those variables (nil) so that they don’t get mixed up in some other way later.
Hope this helps,
Brent