Why am i getting this error in this code

This is a very important question due to the fact i don’t know what this error means, it would be much appreciated if i could have any assistance, that is my code.

MY ERROR

File: error loading module ‘level2’ from file ‘level2.lua’

Error loading module ‘level2’ from file ‘/Users/Bhupinder/Desktop/Old Desktop items not in use/carisma/move/testin/done/level2.lua’:

/Users/Bhupinder/Desktop/Old Desktop items not in use/carisma/move/testin/done/level2.lua:53: ‘then’ expected near ‘end’

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

level1.lua:44: in function <level1.lua:37>

?: in function ‘dispatchEvent’

?: in function ‘_nextTransition’

?: in function <?:1492>

(tail call): ?

?: in function <?:498>

?: in function <?:221>

MY CODE

[lua]local composer = require(“composer”)

local scene = composer.newScene()

local myData = require(“myData”)

local field

– “scene:create()”
function scene:create( event )

local sceneGroup = self.view

– Initialize the scene here.
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
end

– “scene:show()”
function scene:show( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will”) then

local secondsLeft = 20 * 60 – 20 minutes * 60 seconds

local clockText = display.newText(“20:00”, display.contentCenterX, 80)

local function updateTime()
– decrement the number of seconds
secondsLeft = secondsLeft - 1

– time is tracked in seconds. We need to convert it to minutes and seconds
local minutes = math.floor( secondsLeft / 60 )
local seconds = secondsLeft % 60

– make it a string using string format.
local timeDisplay = string.format( “%02d:%02d”, minutes, seconds )
clockText.text = timeDisplay
if timeDisplay == “19:40” then
if field then
field:removeSelf()
elseif
field2:removeSelf()
end
clockText:removeSelf()
composer.gotoScene(“menu”)

end

– run them timer
local countDownTimer = timer.performWithDelay( 1000, updateTime, secondsLeft )

local function textListener( event )

local txt = event.target.text

if ( event.phase == “ended” or event.phase == “submitted”) then

end

end

end
field = native.newTextField ( 150, 150, 180, 30)
field:addEventListener(“userInput”, textListener)
field.autocorrectionType = “UITextAutocorrectionTypeNo”

elseif ( phase == “did”) then

end

end

– “scene:hide()”
function scene:hide( event )

local sceneGroup = self.view
local phase = event.phase

if ( phase == “will” ) then

– Called when the scene is on screen (but is about to go off screen).
– Insert code here to “pause” the scene.
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen.
end
end

– “scene:destroy()”
function scene:destroy( event )

local sceneGroup = self.view

– Called prior to the removal of scene’s view (“sceneGroup”).
– Insert code here to clean up the scene.
– Example: remove display objects, save state, etc.
end


– Listener setup

scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )


return scene[/lua]

Im sorry but your going to have to clean your code up a bit if you want someone to help… Its a big mess and there are functions that i see no “end” too…

Put your code into something like this?..

local composer = require("composer") local scene = composer.newScene() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did") then end end scene:addEventListener( "show", scene ) return scene

Good Luck!

that has a end the problem in the coded is local textlistiner function

Try changing the “else if” on line 30 above to just an “else”. That will give an error like you’re getting. Beyond that with out properly indented code, we can’t make sense out of what end’s go with ifs, functions, loops etc. See this tutorial: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/

Im sorry but your going to have to clean your code up a bit if you want someone to help… Its a big mess and there are functions that i see no “end” too…

Put your code into something like this?..

local composer = require("composer") local scene = composer.newScene() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did") then end end scene:addEventListener( "show", scene ) return scene

Good Luck!

that has a end the problem in the coded is local textlistiner function

Try changing the “else if” on line 30 above to just an “else”. That will give an error like you’re getting. Beyond that with out properly indented code, we can’t make sense out of what end’s go with ifs, functions, loops etc. See this tutorial: https://coronalabs.com/blog/2015/06/09/tutorial-the-value-of-well-formatted-code/