Attempt to index field '?' a nil value error (a different one)

I apologize that it took a while to respond, school just started.

This is not working very well for me, there appears to be heart images left but the player still has lives, and the reduction of lives seems to be occuring twice. 

This is my playerHit():

local function playerHit() timer.cancel(firstTimer) timer.cancel(secondTimer) timer.cancel(moveEnemiesTimer) if livesCount \>= 1 then lives[livesCount].alpha = 0 livesCount = livesCount - 1 print(livesCount) character:setLinearVelocity(0, nil) composer.gotoScene("level1-Try-Again") elseif(livesCount \< 1) then onGameOver() end end

Remove collision listener when going to level 1 try again

Try using a print statemnt in collision function to check whether it is executed two times when coming back to play scene from try again lvl 1 scene

It executes twice when going to level 1 try again. Also, the collision function is removed on scene:hide.

local function playerHit()
timer.cancel(firstTimer)
timer.cancel(secondTimer)
timer.cancel(moveEnemiesTimer)
if livesCount >= 1 then
lives[livesCount].alpha = 0
livesCount = livesCount - 1
print(livesCount)

Runtime:removeEventListener(“collision”,collisionlistener)
character:setLinearVelocity(0, nil)
composer.gotoScene(“level1-Try-Again”)
elseif(livesCount < 1) then
onGameOver()
end
end

The error still occurs, this is what is printed out in the console:

3 2 1 0

The 3 and 2 occurred at the same time.

Can you please zip your game folder and send it to me???By using github or sending me email

hcomb14@gmail.com

I have sent you an email.

Please fix the error that arises when going to level 1 scene

C:\Users\admin\Desktop\Margery Jumps\level1.lua:76: Incorrect number of frames (w,h) = (167,141) with border (0) in texture (w,h) = (500,424). Failed after frame 7 out of 9.

13:09:46.265  stack traceback:

13:09:46.265   [C]: in function ‘error’

13:09:46.265   ?: in function ‘gotoScene’

13:09:46.265   C:\Users\admin\Desktop\Margery Jumps\levelselect.lua:42: in function ‘_onEvent’

13:09:46.265   ?: in function ‘?’

13:09:46.265   ?: in function <?:449>

13:09:46.265   ?: in function <?:169>

I have sent the new email.

That error still occurs

it is better advised to have number of columns that can be divided by the width of the image easily… There should be no decimals like you have placed in following code

local beetleSheetData = {width=166.67, height=106, numFrames=10, sheetContentWidth=500, sheetContentHeight=424}

Okay so figured out your problem

It lies here in this piece of code:

physics.addBody(enemy, "dynamic", physicsData:get("beetle")) physics.addBody(enemy2, "dynamic", physicsData:get("vulture")) physics.addBody(enemy3, "dynamic", physicsData:get("scorpion")) physics.addBody(enemy4, "dynamic", physicsData:get("bee")

Due to this, your collision function is been called twice or maybe thrice

Instead of using complex shapes, i replaced them by using normal shapes

physics.addBody(enemy, "dynamic") physics.addBody(enemy2, "dynamic") physics.addBody(enemy3, "dynamic") physics.addBody(enemy4, "dynamic")

This code worked for me !! This code reduces one life when colliding with enemy…

See this guide:

https://docs.coronalabs.com/daily/guide/physics/physicsBodies/index.html

it will help you in defining shapes for your physics bodies

Hope this helped you :smiley:

Yes, but using normal shapes makes it look very unrealistic, it appears as if the character is colliding with thin air.

I see you can create polygons, but I am very bad with coordinates…

You have to… Thats the only way…

When you said the player only loses one life, did you try it multiple times?

yes i tried it multiple times

Since lives 3 and 2 are lost at the same time and changing the physics bodies to a single simple shape seems to address this, it sounds like perhaps you’re creating the multiple physics bodies so that they are separate physics bodies and not just one body. Are you using Physics Editor to generate the physics bodies?

If so, you might want to consider using it to generate simple polygons. When I let it auto trace the ships in my game, it was creating shapes that were causing errors. If you delete the auto-generated shape and click on the polygon button it will give you a triangle in the bottom right. you can drag each of the 3 points to logical places on the object. You can right-click (CTRL-Click on a Mac) to add additional points until you get your shape. See one of my pieces below:

You end up with a better fitting shape with out the complexities through you give up some perfection like around the wings on the backside of the ship.

Rob