Why am i getting this error?

It looks like your booton:touch function is missing an “end”.
You have an if/elseif which has no “end”, so the end that you have written for the function is being used for the if statement instead.

Can you copy and paste my code and add the end where they are supposed to go? I dont know where to exactly put them.
Thank you.

I’m on my phone so you’ll have to excuse any poor formatting here:

function booton:touch(event)
if event.phase == “began” then
elseif event.phase == “ended” then
storyboard.gotoScene(“level1”, “fade”, 500)
end --add an end here to close your if/elseif
return true
end --now this closes your function

Thank you alan ill see if it works

I am getting a different error which means one problem was solved I will post the error in another topic

Actually I gave you some bad advice last night.  I normally use function handlers you’re using object handlers.  Your booton:touch() function has to after the booton = display.newImage() call in the createScene function.

Rob

I am still getting an error .

Error :

Windows simulator build date: Nov 18 2014 @ 18:35:32

Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
error loading module ‘menu’ from file ‘c:\users\true\documents\corona projects\b
ouncy balls\menu.lua’:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:9: ‘<eof>’
 expected near ‘end’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

Menu,lua code :

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() if event.phase == "began" then elseif event.phase == "ended" then storyboard.gotoScene("level1", "fade", 500) end return true end function scene:createScene( event ) local group = self.view -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 -- display play button local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 local booton = display.newImage( "booton.png" ) booton.x = 160 booton.y = 400 function booton:touch(event) group:insert( background ) group:insert( ground ) group:insert( button ) group:insert( logo ) group:insert(booton) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end booton:addEventListener("touch", booton) scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene 

level 1.lua code ( if needed at this point) :

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local group = self.view local physics = require( "physics" ) physics.start() physics.setGravity(0, 7) -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) -- create object local myObject = display.newRect( 0, 0, 100, 30 ) myObject:setFillColor( 0 ) myObject.x = 145; myObject.y = 400 physics.addBody( myObject, "kinematic" , { myObject, friction=0.5, bounce=1 } ) -- touch listener function function myObject:touch( event ) if event.phase == "moved" then self.x = event.x self.y = event.y end return true end -- make 'myObject' listen for touch events myObject:addEventListener( "touch", myObject ) -- display ball image local ball = display.newImageRect( "ball.png", 81, 60 ) ball.x, ball.y = 145, 200 ball.rotation = .5 -- add physics to the ball physics.addBody( ball, { "dynamic" ,density=1000, friction=0.3, bounce=0.1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 387 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 300 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 202 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 104 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 7 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 50, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 135, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 232 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 335 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 3 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 98 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 325 wall.y = 195 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 292 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 387 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=4 } ) group:insert(background) group:insert(ground) group:insert(myObject) group:insert(ball) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

Im sorry for bugging but what changes do I need now .

Thank you so much.

Alright, try this  – replace lines 30-32 of menu.lua with this:

 local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 function booton:touch(event) if event.phase == "ended" then storyboard.gotoScene("level1", "fade", 500) end return true end booton:addEventListener("touch", booton)

Then remove lines 4-9 and 55.    Lines 4-9 are the partial function you moved.  Line 55 is where you enable the touch handler (needs to be with the touch handler),  and you moved the function from the top to createScene like I said, you only moved the function definition, you didn’t move the whole functions.  I cleaned up the touch function a bit.

Rob

still having this error :

Windows simulator build date: Nov 18 2014 @ 18:35:32

Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
error loading module ‘menu’ from file ‘c:\users\true\documents\corona projects\b
ouncy balls\menu.lua’:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: ‘(’ ex
pected near ‘:’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

menu.lua code:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local group = self.view -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 -- display play button local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 local function booton:touch(event) if event.phase == "ended" then storyboard.gotoScene("level1", "fade", 500) end return true end booton:addEventListener("touch", booton) group:insert( background ) group:insert( ground ) group:insert( button ) group:insert( logo ) group:insert(booton) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

level1.lua code:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local group = self.view local physics = require( "physics" ) physics.start() physics.setGravity(0, 7) -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) -- create object local myObject = display.newRect( 0, 0, 100, 30 ) myObject:setFillColor( 0 ) myObject.x = 145; myObject.y = 400 physics.addBody( myObject, "kinematic" , { myObject, friction=0.5, bounce=1 } ) -- touch listener function function myObject:touch( event ) if event.phase == "moved" then self.x = event.x self.y = event.y end return true end -- make 'myObject' listen for touch events myObject:addEventListener( "touch", myObject ) -- display ball image local ball = display.newImageRect( "ball.png", 81, 60 ) ball.x, ball.y = 145, 200 ball.rotation = .5 -- add physics to the ball physics.addBody( ball, { "dynamic" ,density=1000, friction=0.3, bounce=0.1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 387 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 300 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 202 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 104 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = -6, 7 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 50, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x, wall.y = 135, -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 232 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 335 wall.y = -49 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 3 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 98 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.x = 325 wall.y = 195 wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 292 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=1 } ) local wall = display.newImageRect( "wall.png", 100, 10 ) wall.rotation = 90 wall.x = 325 wall.y = 387 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=4 } ) group:insert(background) group:insert(ground) group:insert(myObject) group:insert(ball) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) group:insert(wall) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

What is the problem here everything looks correct.

Thank you.

First, no need to post your level1.lua code until we need to see it.  Second, try taking the “local” off of the function definition.  Since you’re doing an object handler, you’re not creating a new variable, but adding the touch function to the booton object.

Rob

I didn’t have that before and I got this.

Windows simulator build date: Nov 18 2014 @ 18:35:32

Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
error loading module ‘menu’ from file ‘c:\users\true\documents\corona projects\b
ouncy balls\menu.lua’:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: ‘(’ ex
pected near ‘:’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: attempt to ind
ex global ‘booton’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: in fun
ction <c:\users\true\documents\corona projects\bouncy balls\menu.lua:4>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: attempt to ind
ex global ‘booton’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: in fun
ction <c:\users\true\documents\corona projects\bouncy balls\menu.lua:4>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

Copyright © 2009-2014  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2014.2511
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2014.2511
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
Runtime error
c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: attempt to ind
ex global ‘booton’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy balls\menu.lua:25: in fun
ction <c:\users\true\documents\corona projects\bouncy balls\menu.lua:4>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy balls\main.lua:16: in mai
n chunk

Can you post your current menu.lua?   What is line 25 of that file?

all of menu.lua code:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event ) local group = self.view -- display background image local background = display.newImage( "background.png" ) background.x = 10; background.y = 308 -- display ground image local ground = display.newImage( "ground.png" ) ground.x = 145; ground.y = 480 -- display play button local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 function booton:touch(event) if event.phase == "ended" then storyboard.gotoScene("level1", "fade", 500) end return true end booton:addEventListener("touch", booton) group:insert( background ) group:insert( ground ) group:insert( button ) group:insert( logo ) group:insert(booton) end function scene:enterScene( event ) local group = self.view end function scene:exitScene( event ) local group = self,view end function scene:destroyScene( event ) local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene 

and im having the same error as last posted.( sorry for posting late I had to go somewhere).

 -- display play button local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 -- display logo image local logo = display.newImageRect( "logo.png", 300, 200 ) logo.x = 160 logo.y = 20 local button = display.newImageRect( "button.png", 100, 80 ) button.x = 160 button.y = 300 function booton:touch(event) if event.phase == "ended" then storyboard.gotoScene("level1", "fade", 500) end return true end booton:addEventListener("touch", booton)

I don’t want to sound mean, but if you took a minute to look over your code, this should be rather obvious.

First on line 16 you create a display object called “button”.   Then again on line 23, you write over “button” with a different display object.  In previous versions of your code you called this “booton” not button.   In line 25 you are trying to add a touch handling function to an object named “booton” which you are no longer creating, instead you’ve renamed it to button. 

Your options:  either rename the second object “booton” or rename the touch function to use “button” instead of “booton”.  But in either case, you have to deal with the fact that you’re trying to use “button” for two different things.

“button” is a very bad variable name (in particular when you have multiple buttons!).  How about naming it “playButton” (I think you only have the one button, but you did it twice). 

Have you read our recent blog post on formatting your code?

https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

Rob

THANK YOU SO MUCH ROB IT WORKED. And im sorry for not looking my code over carefully enough. I CAN NOT THANK YOU ENOUGH. My best wishes.
Thank you.