'<eof>' error In Tutorial

Working my way through the Star Explorer tutorial, and when I finished the ship dragging code, it suggests to try it out. 
When I do I get an error, that says:

main.lua:165: ‘<eof’ expected near 'end’

I’ve gone through the code multiple times, but I can’t figure out where I went wrong. I am kind of hesitant to continue in case the error is persistent.

Below is my code. 

Any help would be appreciated.

Thanks,

Patrick

[spoiler]

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local physics = require "physics" physics.start() physics.setGravity( 0, 0 ) -- Seed the random number generator math.randomseed( os.time() ) -- Configure Image Sheet local sheetOptions = { frames = { { -- 1) Asteroid 1 x = 0, y = 0, width = 102, height = 85 }, { -- 2) Asteroid 2 x = 0, y = 85, width = 90, height = 83 }, { -- 3) Asteroid 3 x = 0, y = 168, width = 100, height = 97 }, { -- 4) Ship x = 0, y = 265, width = 98, height = 79 }, { -- 5) Laser x = 98, y = 265, width = 14, height = 40 }, }, } local objectSheet = graphics.newImageSheet( "gameObjects.png", sheetOptions ) -- Initialize Variables local lives = 3 local score = 0 local died = false local asteroidsTable = {} local ship local gameLoopTimer local livesText local scoreText -- Set Up Display Groups local backGroup = display.newGroup() -- Display Group for background image local mainGroup = display.newGroup() -- Display Group for ship, asteroids, lasers, etc. local uiGroup = display.newGroup() -- Display Group for UI objects like the score --Load the background local background = display.newImageRect( backGroup, "background.png", 800, 1400) background.x = display.contentCenterX background.y = display.contentCenterY ship = display.newImageRect( mainGroup, objectSheet, 4, 98, 79) ship.x = display.contentCenterX ship.y = display.contentHeight - 100 physics.addBody( ship, {radius=30, isSensor=true} ) ship.myName = "ship" --Display Lives and Score livesText = display.newText( uiGroup, "Lives: " .. lives, 200, 80, native.systemFont, 36 ) scoreText = display.newText( uiGroup, "Score: " .. score, 400, 80, native.systemFont, 36 ) --Hide Status bar display.setStatusBar( display.HiddenStatusBar ) local function updateText() livesText.text = "Lives: " .. lives scoreText.text = "Score: " .. score end local function createAsteroid() local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 ) table.insert( asteroidsTable, newAsteroid ) physics.addBody( newAsteroid, "dynamic", {radius=40, bounce=0.8} ) newAsteroid.myName = "asteroid" local whereFrom = math.random( 3 ) if ( whereFrom == 1 ) then --From the left newAsteroid.x = -60 newAsteroid.y = math.random( 500 ) newAsteroid:setLinearVelocity( math.random( 40,120), math.random( 20,60) ) elseif ( whereFrom == 2 ) then --From the Top newAsteroid.x = math.random( display.contentWidth ) newAsteroid.y = -60 newAsteroid:setLinearVelocity ( math.random( -40,40 ), math.random( 40,120 ) ) elseif ( whereFrom == 3 ) then --From the Right newAsteroid.x = display.contentWidth + 60 newAsteroid.y = math.random( 500 ) newAsteroid:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) end newAsteroid:applyTorque( math.random( -6,6 ) ) end local function fireLaser() local newLaser = display.newImageRect( mainGroup, objectSheet, 5, 14, 40 ) physics.addBody( newLaser, "dynamic", { isSensor=true } ) newLaser.isBullet = true newLaser.myName = "laser" newLaser.x = ship.x newLaser.y = ship.y newLaser:toBack() transition.to( newLaser, { y=-40, time=500, onComplete = function() display.remove( newLaser ) end } ) end ship:addEventListener( "tap", fireLaser ) local function dragShip( event ) local ship = event.target local phase = event.phase if ( "began" == phase ) then --set touch focus on the ship display.currentStage:setFocus ( ship ) -- store initial offset position ship.touchOffsetX = event.x - ship.x elseif ( "moved" == phase ) then --Move ship to new touch position ship.x = event.x - ship.touchOffsetX elseif ( "ended" == phase or "cancelled" == phase) then --release touch focus in the Ship display.currentStage:setFocus( nil ) end return true --prevents touch propagation to underlying objects end ship:addEventListener( "touch", dragShip )

[/spoiler]

The following error does not exist in the code you pasted.

Unless I remember that error wrong, it simply means that you have (or had) an extra “end” somewhere in your code. But, as I said, I ran the code and there isn’t an error there. If, for some reason, you still have a problem, then consider zipping and uploading the project folder here so that we can run the same code that you have.

Thanks.

I ended up cutting the dragShip function out, then pasting it back in, and the error went away. Not sure what the issue was. 

The following error does not exist in the code you pasted.

Unless I remember that error wrong, it simply means that you have (or had) an extra “end” somewhere in your code. But, as I said, I ran the code and there isn’t an error there. If, for some reason, you still have a problem, then consider zipping and uploading the project folder here so that we can run the same code that you have.

Thanks.

I ended up cutting the dragShip function out, then pasting it back in, and the error went away. Not sure what the issue was.