Hello!
The help last time was really quick and useful, so I will try again:)
I´m dropping different objects from top to bottom and the player must catch them with characters tongue. If they hit ground they should be removed (simplified explanation).
Now the problem is that if the objects are falling with a very short interval and hit the ground, I get a runtime error:
WARNING: Attempting to set property(x) with nil
WARNING: Attempting to set property(y) with nil
Runtime error
..\level3.lua:27: attempt to
index field 'parent' (a nil value)
stack traceback:
[C]: ?
...level3.lua:27: in function '\_listener'
?: in function <?:514ground hit<br>
If the interval is longer, for example there is a one or two second cap between the ground collisions, no error is displayed and all works fine. Also there is no error if I don´t remove the object (line 27 in here).
[lua]–***************************************************
– BEE CREATION, COLLISION & DROP
–***************************************************
local onbeeCollision = function( self, event )
if (event.other.myName == “tongue” and event.target.myName == “bee” or event.other.myName == “ground”) then
local doCollision = function()
audio.play( bugCaughtSound )
self.isHit = true
print( “bee destroyed!”)
self.isVisible = false
self.isBodyActive = false
eatenBug.x = self.x; eatenBug.y = self.y
eatenBug.alpha = 0
eatenBug.isVisible = true
local fadebug = function()
transition.to( eatenBug, { time=500, alpha=0 } )
end
transition.to( eatenBug, { time=50, alpha=1.0, onComplete=fadebug } )
timer.performWithDelay( 50, resetTongue )
self.parent:remove( self )
self = nil
end
–COLLISION TIMER
local collisionTimer = timer.performWithDelay( 1, doCollision, 1 )
if event.other.myName == “character” then
bugCount = bugCount + 1
bugText.text = "Catched: " … tostring( bugCount )
bugText.xScale = 0.5; bugText.yScale = 0.5
bugText.x = (480 - (bugText.contentWidth * 0.5)) - 15
bugText.y = 305
print(“bee caught”)
local newScore = gameScore + 2
setScore( newScore )
elseif event.other.myName == “tongue” then
bugCount = bugCount + 1
bugText.text = "Caught: " … tostring( bugCount )
bugText.xScale = 0.5; bugText.yScale = 0.5
bugText.x = (480 - (bugText.contentWidth * 0.5)) - 15
bugText.y = 305
print(“bee caught”)
local newScore = gameScore + 2
setScore( newScore )
elseif event.other.myName == “ground” then
print(“Ground hit!”)
end
end
end
–BEE DROP
local beeDrop = function()
local displayScale = display.contentScaleX
if displayScale < 1 then
beeSheet = sprite.newSpriteSheet( “images/beeSprite@2x.png”, 130, 120 )
else
beeSheet = sprite.newSpriteSheet( “images/beeSprite.png”, 65, 60 )
end
local spriteSet1 = sprite.newSpriteSet(beeSheet, 1, 2)
sprite.add( spriteSet1, “move”, 1, 2, 100, 0 )
bee = sprite.newSprite( spriteSet1 )
if displayScale < 1 then
bee.xScale = .5; bee.yScale = .5
end
bee.x = display.contentWidth / 2
bee.y = display.contentHeight / 2
bee:prepare(“move”)
bee:play()
bee.x = mRand( 80, 450 ); bee.y = -40
transition.to( bee, { time=mRand(1500, 2000), y = 400, transition=easing.linear } )
bee.isHit = false
physics.addBody( bee, “dynamic”,{ density=beeDensity, bounce=0, friction=0.5, shape=bugShape } )
bee.isFixedRotation = true
bee.myName = “bee”
gameGroup:insert( bee )
bee.postCollision = onbeeCollision
bee:addEventListener( “postCollision”, bee )
counter:toFront()
pauseBtn:toFront()
scoreText:toFront()
bugText:toFront()
end
– CREATE NEW BEE
local beeTimer = function()
startDrop = timer.performWithDelay( mRand(1000, 1500), beeDrop, 0 )
end[/lua]
So maybe someone has an idea?
Thanks in advance!
Gert [import]uid: 105289 topic_id: 30429 reply_id: 330429[/import]