transition VS. onComplete is causing a problem

For some reason, i cannot return the object transmitted in the transition.to

The following function is generating a bullet and once it generated i want it to be removed after completion of the transition action. I got the following error
[blockcode]
Runtime error
/Development/starwar/library.lua:44: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
/Development/starwar/library.lua:44: in function
(tail call): ?
?: in function <?:866>
?: in function <?:214>
[/blockcode]
instantiate Bulle Function:-

[blockcode]
function instantiateBullet()
bullet = movieclip.newAnim(1,{rocketImages…“rocket2.png”})
–bullet = display.newImage(rocketImages…“rocket2.png”)
local _=lineObject
local bulletHightCeeling,bulletWidthCeeling = _.y + 1, _.width-10
print (0, 0, bulletWidthCeeling, bulletHightCeeling )
–bullet:setDrag{drag=false,bounds = {15, bulletWidthCeeling, bulletWidthCeeling, bulletHightCeeling }} --left, top, width, height
bullet.objectName=“bullet”;
bullet.isVisible = true
bullet.y = spaceShip.y - 65; bullet.x = spaceShip.x
physics.addBody(bullet,{bounce = 0.3, fraction=1.0, denisty=0.0 })
playSound(“lazer.caf”)
–bullets[#bullets+1] = bullet
bullet.collision = onCollision
bullet:addEventListener( “collision”, bullet)
nemesisGroup:insert(bullet)
print(bullet.x)
transition.to(transition.to(bullet,{time=1000, delay=10, alpha=1.0, y=28,
onComplete= function() bullet:removeSelf() end}))
return bullet
end
[/blockcode] [import]uid: 11038 topic_id: 3997 reply_id: 303997[/import]

why

[lua]transition.to(transition.to([/lua]

?! [import]uid: 6645 topic_id: 3997 reply_id: 12131[/import]

i was trying to delay the transition for 2 seconds.
[import]uid: 11038 topic_id: 3997 reply_id: 12149[/import]

Its a scope problem, definately.

I take it that there could be several bullets active at the same time. Read up the transition.to description. Use the target param for the oncomplete handler, instead of using bullet directly. Bullet will be nil after the first time you removed something. [import]uid: 5712 topic_id: 3997 reply_id: 12158[/import]

Thanks MikeHart! This is exactly my problem. Forget about the transition.to duplicate, i already fixed that. My problem is how to solve the problem im facing when i need to generate several bullets and once every bullet reaches the y=28 i want to remove only that particular bullet. As you know, my app will be sending random bullets based on “onTouch” event listener. So i just need to know how to fix my code to remove only the bullet arrived to that point.

Thanks my friend for your co-operation.

I love you guys :slight_smile: [import]uid: 11038 topic_id: 3997 reply_id: 12160[/import]

[lua]local function removeBullet(obj)
obj:removeSelf()
end
end

local function instantiateBullet()

local bullet = movieclip.newAnim(1,{rocketImages…“rocket2.png”})

transition.to(bullet,{time=1000, delay=2000, alpha=1.0, y=28, onComplete=removeBullet})

return bullet
end[/lua]

[import]uid: 6645 topic_id: 3997 reply_id: 12172[/import]

Looking at the code above the call to removeBullet doesn’t pass in an obj [import]uid: 9371 topic_id: 3997 reply_id: 12173[/import]

It’s right. The transition passes it. Try it [import]uid: 6645 topic_id: 3997 reply_id: 12174[/import]

Hi again jmp909,
it didn’t work, im still getting the same error message: see below:-
[blockcode]
function instantiateBullet()
local bullet = movieclip.newAnim(1,{rocketImages…“rocket2.png”})
bullet.objectName=“bullet”;
bullet.isVisible = true
bullet.y = spaceShip.y - 65; bullet.x = spaceShip.x
physics.addBody(bullet,{bounce = 0.3, fraction=1.0, denisty=0.0 })
playSound(“lazer.caf”)
bullet.collision = onCollision
bullet:addEventListener( “collision”, bullet)
nemesisGroup:insert(bullet)
transition.to(bullet,{time=1000, delay=10, alpha=1.0, y=28, onComplete=removeBullet})
return nbullet
end

function removeBullet(obj)
print(“name”…obj.objectName)
obj:removeSelf()
end
spaceShip:addEventListener(“tap”, instantiateBullet)
[/blockcode]

Note: space ship is the event that fires the bullet. [import]uid: 11038 topic_id: 3997 reply_id: 12177[/import]

Sorry forgot to pass the error:-
[blockcode]
Runtime error
/Development/starwar/main.lua:200: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
/Development/starwar/main.lua:200: in function
(tail call): ?
?: in function <?:866>
?: in function <?:214>
namebullet
Runtime error
/Development/starwar/main.lua:200: attempt to call method ‘removeSelf’ (a nil value)
stack traceback:
[C]: in function ‘removeSelf’
/Development/starwar/main.lua:200: in function
(tail call): ?
?: in function <?:866>
?: in function <?:214>

[/blockcode] [import]uid: 11038 topic_id: 3997 reply_id: 12178[/import]

WOW! That’s cool. I wish the docs mentioned this! :frowning: [import]uid: 9371 topic_id: 3997 reply_id: 12179[/import]

Thanks i solved it in an other way. [import]uid: 11038 topic_id: 3997 reply_id: 12185[/import]

Post your solution for others please, pretty please :wink: [import]uid: 9371 topic_id: 3997 reply_id: 12186[/import]

You didn’t define your removebullet function until *after* you call it. This won’t work, unless you add this at the top of your file

[lua]local removeBullet[/lua]

Before your instantiatebullet function at least. Or simpler just to move the removebullet function above the instantiatebullet function in the first place [import]uid: 6645 topic_id: 3997 reply_id: 12188[/import]

Really!! I didn’t expect this step. i’ll try this and will let you know. Thanks
jmp909, please one more thing! my simulator was working perfectly when ever i open a project using the corona terminal, the simulator (iphone) opens maximized by default. For some reasons, now it opens minimized and i need to click on command+= (Zoom in option from the main menu) to maximize the simulator (iphone). This however, makes me do this every time whenever i click on command+r (File> Relaunch) .

Any suggestions to fix this issue.

Thanks [import]uid: 11038 topic_id: 3997 reply_id: 12189[/import]

I’m having a similar issue, how did you solve it? [import]uid: 12455 topic_id: 3997 reply_id: 20109[/import]

I’m also having this issue, how did you solve it? [import]uid: 14018 topic_id: 3997 reply_id: 34072[/import]