Hi,
I am using a physics body with and storyboard.
The first time the scene is displayed, the physics litener for collisions works fine. But after destroying and creating again the scene i displays an error
.lua:66: attempt to index field ‘object2’ (a nil value)
I have made many attempts but i have no idea about what is causing this error. the scene is removed completely by removeScene and all the listeners transitions are cancelled.
I put my code.
THANKS FOR ANY SUGGESTION
local function novaPilota(x)
local radi=34\*0.417
local tipusPilota=math.random(1,6)
suma=math.random(-1,1)
local pilota=display.newImageRect("ARCADE PILOTA "..tipusPilota..".png", 28, 28)
--pilotes belongs to the scene group
pilotes:insert(pilota)
pilota.name="pilota"
pilota.x, pilota.y = (x-radi+suma)\*0.417,320-672\*0.417
--HERE ADD THE BODY
physics.addBody(pilota,{ friction=0.3, bounce=0.2, radius=radi })
pilota.inremove=false
function pilota:remove()
if (not self.inremove) then
self.inremove=true
table.insert(transitionList,
transition.to( self, { time=1000, transition=easing.inExpo, delay=1500, alpha=0,
onComplete=function()
self:removeSelf() end }
)
)
end
end
end
function onCollision( event )
if ( event.phase == "began" ) then
local name1=event.object1.name
--crashes when trying to access object2
local name2=event.object2.name
print(name1.." "..name2)
if ( event.object1.name=="marc" ) then
event.object2:remove()
elseif ( event.object2.name=="marc" ) then
event.object1:remove()
elseif ( event.object1.name=="cistell" ) then
event.object2:removeSelf()
event.object2=nil
animacioMarcador:actualitzar()
elseif ( event.object2.name=="cistell" ) then
event.object1:removeSelf()
event.object1=nil
animacioMarcador:actualitzar()
end
end
end
--everything is destroyed
function scene:exitScene( event )
local group = self.view
-----------------------------------------------------------------------------
Runtime:removeEventListener( "retornjoc", self )
timer.cancel(timer1)
timer.cancel(timer2)
timer.cancel(timer3)
spriteFinal:dispose()
CIL:destruir()
for i,t in ipairs(transitionList) do
print (i)
transition.cancel(t)
end
-----------------------------------------------------------------------------
end
thanks!
[import]uid: 76413 topic_id: 20244 reply_id: 320244[/import]
[import]uid: 84637 topic_id: 20244 reply_id: 79169[/import]