Chapter 3 — Bringing it to Life

Hi, 

I’m back again, I just finished chapter 3 slow and steady, but I keep receiving an elseif error message.  Everything prior to local function onCollision( event ) works, I checked google and it’s says that I’m missing an “end” after the if statement. I’ve added ends, removed ends, but no go.

I added a snippet.

I appreciate any help, 

Thanks.

Remove that end in line 250

Removing  that end at 250 won’t fix it. Your end placements are everywhere it seems. On line 231 you ended off your function but it should have ended at 272

If you post the code here I’ll fix the end’s for you.

Actually I just went to the docs to find the chapter

local function onCollision( event ) if ( event.phase == "began" ) then local obj1 = event.object1 local obj2 = event.object2 if ( ( obj1.myName == "laser" and obj2.myName == "asteroid" ) or ( obj1.myName == "asteroid" and obj2.myName == "laser" ) ) then -- Remove both the laser and asteroid display.remove( obj1 ) display.remove( obj2 ) for i = #asteroidsTable, 1, -1 do if ( asteroidsTable[i] == obj1 or asteroidsTable[i] == obj2 ) then table.remove( asteroidsTable, i ) break end end -- Increase score score = score + 100 scoreText.text = "Score: " .. score elseif ( ( obj1.myName == "ship" and obj2.myName == "asteroid" ) or ( obj1.myName == "asteroid" and obj2.myName == "ship" ) )then if ( died == false ) then died = true -- Update lives lives = lives - 1 livesText.text = "Lives: " .. lives if ( lives == 0 ) then display.remove( ship ) else ship.alpha = 0 timer.performWithDelay( 1000, restoreShip ) end end end end end

It works!! 

I really appreciate you helping me, I rechecked the chapter there are 2 ends after local obj1 = event.object1 and local obj2 = event.object2, I just copying from the site. The instructions are a little confusing, I can’t find any beginner classes and this site made a big jump from making a balloon go high to blasting asteroids, not really beginner stuff.

Where did you learn Lua?

Thanks.

I learned Lua from Roblox.com but I felt like there was no benifits from being on that site so I went to another platform.

I always suggest this guy when learning a new language

https://www.youtube.com/watch?v=iMacxZQMPXs

Thanks again for the help and the learning info.

Remove that end in line 250

Removing  that end at 250 won’t fix it. Your end placements are everywhere it seems. On line 231 you ended off your function but it should have ended at 272

If you post the code here I’ll fix the end’s for you.

Actually I just went to the docs to find the chapter

local function onCollision( event ) if ( event.phase == "began" ) then local obj1 = event.object1 local obj2 = event.object2 if ( ( obj1.myName == "laser" and obj2.myName == "asteroid" ) or ( obj1.myName == "asteroid" and obj2.myName == "laser" ) ) then -- Remove both the laser and asteroid display.remove( obj1 ) display.remove( obj2 ) for i = #asteroidsTable, 1, -1 do if ( asteroidsTable[i] == obj1 or asteroidsTable[i] == obj2 ) then table.remove( asteroidsTable, i ) break end end -- Increase score score = score + 100 scoreText.text = "Score: " .. score elseif ( ( obj1.myName == "ship" and obj2.myName == "asteroid" ) or ( obj1.myName == "asteroid" and obj2.myName == "ship" ) )then if ( died == false ) then died = true -- Update lives lives = lives - 1 livesText.text = "Lives: " .. lives if ( lives == 0 ) then display.remove( ship ) else ship.alpha = 0 timer.performWithDelay( 1000, restoreShip ) end end end end end

It works!! 

I really appreciate you helping me, I rechecked the chapter there are 2 ends after local obj1 = event.object1 and local obj2 = event.object2, I just copying from the site. The instructions are a little confusing, I can’t find any beginner classes and this site made a big jump from making a balloon go high to blasting asteroids, not really beginner stuff.

Where did you learn Lua?

Thanks.

I learned Lua from Roblox.com but I felt like there was no benifits from being on that site so I went to another platform.

I always suggest this guy when learning a new language

https://www.youtube.com/watch?v=iMacxZQMPXs

Thanks again for the help and the learning info.