Error: 'end' expected (to close 'function' at line 75) near '<eof>'

Hi guys,

I’ve been trying to figure out what the error for nearly two days but I can’t do so. I’m getting the error below:

‘end’ expected (to close ‘function’ at line 75) near ‘<eof>’

I can’t find any ‘ends’ missing, and furthermore my <function()>s are all closed with end. 

I’m a complete noob so expect this question to be stupid :stuck_out_tongue:
Please help me solve this error!

Code: 

– Description: 

– Version: 1.0

– Managed with http://CoronaProjectManager.com

– Copyright 2015 . All Rights Reserved.

– 

----- references

local repeat1

local  repeat2

------preload audio

local bmusic = audio.loadSound(“Background.wav”)

local blast = audio.loadSound(“blast.mp3”)

local boing = audio.loadSound(“boing-1.wav”)

------ sprite sheet

local options = 

{

width = 120 ,

height = 120,

numFrames = 36,

sheetContentWidth = 1080,

sheetContentHeight = 480

}

local sheet = graphics.newImageSheet(“SpriteSheet1stgame.png”,options)

local bg = display.newImage(sheet,25)

bg.x = display.contentCenterX

bg.y = display.contentCenterY

bg.xScale=10

bg.yScale=5

--------individual frame creation for game start

local frameSaveBlob = display.newImage(sheet,17 )

frameSaveBlob.x = display.contentCenterX-150

frameSaveBlob.y =180

frameSaveBlob.xScale=2

frameSaveBlob.yScale=2

local qg = display.newImage(sheet,23)

qg.x = display.contentCenterX + 100

qg.y = display.contentCenterY  +90

qg:scale(1.28,1.28)

local playg = display.newImage(sheet,19)

playg.x = display.contentCenterX + 100

playg.y = display.contentCenterY  - 90

playg:scale(1.28,1.28)

local insg = display.newImage(“UpdateIns.png”)

insg.x = display.contentCenterX + 100

insg.y = display.contentCenterY  

insg:scale(0.32,0.32)

-------- game functions

function repeat1()

transition.cancel(frameSaveBlob.trans)

frameSaveBlob.trans = transition.to(frameSaveBlob, {time=2000, y=150,onComplete=repeat2})

end

function repeat2()

transition.cancel(frameSaveBlob.trans)

frameSaveBlob.trans = transition.to(frameSaveBlob, {time=2000, y=180, delay=50, onComplete=repeat1}) 

end

local function newgame(event)

local playg2 = display.newImage(sheet,20)

playg2.x = display.contentCenterX + 100

playg2.y = display.contentCenterY  - 90

playg2:scale(1.5,1.5)

timer.performWithDelay ( 200, 

function() 

playg2:removeSelf() 

end ,1  )

–timer.performWithDelay ( 200, function() display.remove(playg2) end,1  )

return true

end

local function instruction(event)

local ig2 = display.newImage(sheet,22)

ig2.x = display.contentCenterX + 100

ig2.y = display.contentCenterY 

ig2:scale(1.5,1.5)

timer.performWithDelay ( 200, function() ig2:removeSelf() end ,1  )

–timer.performWithDelay ( 200, function() display.remove(playg2) end,1  )

return true

end

local function quit(event)

local qg2 = display.newImage(sheet,24)

qg2.x = display.contentCenterX + 100

qg2.y = display.contentCenterY +89

qg2:scale(1.5,1.5)

timer.performWithDelay ( 200, function() qg2:removeSelf() end ,1  )

–timer.performWithDelay ( 200, function() display.remove(playg2) end,1  )

return true

end

local function backgroundMusic()

local options = { loops=-1}

audio.play(bmusic, options)

end

----------start_of_game

repeat1()

backgroundMusic()

playg:addEventListener(“tap”,newgame)

insg:addEventListener(“tap”,instruction)

qg:addEventListener(“tap”,quit)

Well your posted code is unformatted and if you had any indentions to help see what block was what, they are long gone.  If you have better formatted code, please repost using the the <> button in the row with Bold, Italic, Underline, etc.  Paste your code into the box that pops up.  It would also help to know what line “line 75” is.

But in a quick scan, it could be these lines: 

timer.performWithDelay ( 200, function() qg2:removeSelf() end ,1 &nbsp;)

Normally I would do it this way:

timer.performWithDelay ( 200, function() qg2:removeSelf(); end ,1 &nbsp;)

Note the semi-colon after the removeSelf() call.  In Lua, when you string multiple statements on one line you generally have to use semi-colons to separate the statements.  On a line by themselves, things are fine.

Rob

Thanks a lot for the reply Rob! 

And sorry about the indentation, I apparently code better without it o.O . Surprisingly, I solved my problem by creating a new project and then adding the same game assets with the lua files. I did get a stack overflow error before but I doubt it has to do anything with the problem. Oh thanks a lot for the above tip! It actually solved my “brackets function()” problem.

Eh, could you suggest me a good IDE for corona? The one I’m working on seems to be sloppy.

Cheers! :D 

I suggest just commenting out large sections of your code starting from the end.  Then uncomment block by block till you see the error re-appear.

You’ll probably find it in the last un-commented block.

Ex:This code is broken:

local function doit() print("HI") end local function run1() doit() return end local function doit() print("HI") end local function run2() doit() return local function run3() doit() return end run1() run2() run3()

Comment out all but the first block:

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] --[[local function run2() doit() return --]] --[[local function run3() doit() return end --]] --[[run1() run2() run3() --]]

…loads fine

Start uncomenting

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] --[[local function run2() doit() return --]] local function run3() doit() return end -- leave comment out; don't run yet --[[run1() run2() run3() --]]

… still loads

Keep going

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] local function run2() doit() return local function run3() doit() return end --[[run1() run2() run3() --]]

Bammm!  Error! 

Must be in that last block…

local function run2() doit() return

 

roaminggamer, that was an amazing advice! Thank you sooo much :slight_smile: I was literally able to debug my large of chunks of code and modules with much more ease than I could’ve ever imagined! :smiley:

Cheers!

However, could you guys suggest me a good IDE for corona? The one that I’m currently working on doesn’t seem to work right.

I use Sublime 3.  Besides Origami and Corona Editor, I don’t install any other plugins.

I do not run my app from Sublime (Tools -> Build … ).  I always launch Corona separately and load my app separately.  

I rarely use the debugger (integrated or otherwise) and reserve that level of running for ‘hard to solve’ issues.  

I second @roaminggamer’s recommendation.  Sublime Text 3 and Corona Editor (I’ll have to check out this Origami) rocks.  The only gotcha is that it doesn’t indent “elseif”'s right.   Like @roaminggamer, I run the simulator as a separate process and debug the old fashion way: print statements…

Rob

Well your posted code is unformatted and if you had any indentions to help see what block was what, they are long gone.  If you have better formatted code, please repost using the the <> button in the row with Bold, Italic, Underline, etc.  Paste your code into the box that pops up.  It would also help to know what line “line 75” is.

But in a quick scan, it could be these lines: 

timer.performWithDelay ( 200, function() qg2:removeSelf() end ,1 &nbsp;)

Normally I would do it this way:

timer.performWithDelay ( 200, function() qg2:removeSelf(); end ,1 &nbsp;)

Note the semi-colon after the removeSelf() call.  In Lua, when you string multiple statements on one line you generally have to use semi-colons to separate the statements.  On a line by themselves, things are fine.

Rob

Thanks a lot for the reply Rob! 

And sorry about the indentation, I apparently code better without it o.O . Surprisingly, I solved my problem by creating a new project and then adding the same game assets with the lua files. I did get a stack overflow error before but I doubt it has to do anything with the problem. Oh thanks a lot for the above tip! It actually solved my “brackets function()” problem.

Eh, could you suggest me a good IDE for corona? The one I’m working on seems to be sloppy.

Cheers! :D 

I suggest just commenting out large sections of your code starting from the end.  Then uncomment block by block till you see the error re-appear.

You’ll probably find it in the last un-commented block.

Ex:This code is broken:

local function doit() print("HI") end local function run1() doit() return end local function doit() print("HI") end local function run2() doit() return local function run3() doit() return end run1() run2() run3()

Comment out all but the first block:

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] --[[local function run2() doit() return --]] --[[local function run3() doit() return end --]] --[[run1() run2() run3() --]]

…loads fine

Start uncomenting

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] --[[local function run2() doit() return --]] local function run3() doit() return end -- leave comment out; don't run yet --[[run1() run2() run3() --]]

… still loads

Keep going

local function doit() print("HI") end --[[local function run1() doit() return end --]] --[[local function doit() print("HI") end --]] local function run2() doit() return local function run3() doit() return end --[[run1() run2() run3() --]]

Bammm!  Error! 

Must be in that last block…

local function run2() doit() return

 

roaminggamer, that was an amazing advice! Thank you sooo much :slight_smile: I was literally able to debug my large of chunks of code and modules with much more ease than I could’ve ever imagined! :smiley:

Cheers!

However, could you guys suggest me a good IDE for corona? The one that I’m currently working on doesn’t seem to work right.

I use Sublime 3.  Besides Origami and Corona Editor, I don’t install any other plugins.

I do not run my app from Sublime (Tools -> Build … ).  I always launch Corona separately and load my app separately.  

I rarely use the debugger (integrated or otherwise) and reserve that level of running for ‘hard to solve’ issues.  

I second @roaminggamer’s recommendation.  Sublime Text 3 and Corona Editor (I’ll have to check out this Origami) rocks.  The only gotcha is that it doesn’t indent “elseif”'s right.   Like @roaminggamer, I run the simulator as a separate process and debug the old fashion way: print statements…

Rob