corona runtime error ( expected near :

hi i’m making an app and im not sure what this error means “main.lua:69 ( expected near :” this is my code

local widget = require( “widget” )

local speedField = native.newTextField( 160, 450 , 150, 30 )


– main.lua


–function to handle button events

local function handleButtonEvent( event )

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

print ( "Speed = " … tonumber(speedField.text) * 2.55 )

local speedText = display.newText( tonumber(speedField.text) * 2.55, 160, 20, native.systemFontBold, 18 )

if speedField.text == “” then

local alert = native.showAlert( “Error”, “No value entered” )

elseif tonumber(speedField.text) == nil then

local alert = native.showAlert( “Error”, “Must be a number” )

elseif tonumber(speedField.text) > 100 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

elseif tonumber(speedField.text) < 1 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

else

end

end

end

–create the widget

local button = widget.newButton(

{

left = 70,

top = 460,

id = “button”,

label = “Continue”,

onEvent = handleButtonEvent

}

)

–Create function for stop button

local function displayStop()

local StopButton = display.newImage(“stop.png”)

StopButton.x = display.contentCenterX

StopButton.y = display.contentCenterY

StopButton.xScale = 0.5

StopButton.yScale = 0.5

function StopButton:touch (event)

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

print("#CS")

local stopText = display.newText( “Stop”, 160, -10, native.systemFontBold, 18 )

end

return true

end

StopButton:addEventListener(“touch”, StopButton)

end

local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code)

local arrow = display.newImage(“arrow.png”)

arrow.x = fullw

arrow.y = fullh

arrow.xScale = centerX

arrow.yScale = centerY

arrow.rotation = rotatione

commande = command

codee = code

local function arrows:touch (event) – add the listener

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

print("#" … command)

local leftForwardText = display.newText( code, 160, -10, native.systemFontBold, 18 )

end

return true

end

end

local fullh = {160, 230, 260, 230, 160, 90, 60, 90}

local fullw = {140, 170, 240, 310, 340, 310, 240, 170}

local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360}

local command = {“Forward”, “Right Forward”, “Hard Right”, “Right Backward”, “Backward”, “Left Backward”, “Hard Left”, “Left Forward”}

local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF}

for i = 1, #fullh do

addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] )

end

displayStop()

  1. Format code posts in the future.

formatyourcode.jpg

  1. The error tells you the line, so the problem is on that line or before it, probably this:

    codee = code – may actually be fine, but probably not what you meant

You have not variable codee…

or line 69:

local function arrows:touch (event) -- (Eagle-eye) Rob has it correct below...

Try commenting out the whole function and see if the problem goes away.

Tip: When you have a problem that is hard to track down, you can

  1. comment out the whole file

  2. slow un-comment in one line at time or one function at a time

Re-load each time.  This will help narrow in on the issue.

PS - Welcome the community, sorry to be short on the first draft of this post.

Hi and welcome to the forums!

You will find more help if you follow a few basic guidelines. First, when posting code, please use the blue <> button in the row with Bold and Italic. Paste your code into the window that pops up. This will format your code making it much easier to read.

Next provide as much information as you can. In this case you have an error saying the problem is in line 69. What line is line 69? Most text editors provide a way to show line numbers making it easy to find. I’m guessing it’s this line:

local function arrows:touch (event) -- add the listener

When adding functions to objects, like with the : operator, the assumption is that the object already exists, in this case arrows, so making it “local” doesn’t make sense because you’ve already declared “arrows” somewhere else.

Try removing the local.

Rob

Hi,

sorry for the formatting i’ll make sure to know for next time and I’ve made a few changes for general tidy up and i now have a new error that says line 79 end expected to close funtion at line 63, however when a add an end it gives me a new error that says main.lua 81 <eof> expected near end. i have put the before and after code below (let me know if i should be starting  new topic for this)

local widget = require( “widget” )

local speedField = native.newTextField( 160, 450 , 150, 30 )


– main.lua


–function to handle button events

local function handleButtonEvent( event )

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

print ( "Speed = " … tonumber(speedField.text) * 2.55 )

if speedField.text == “” then

local alert = native.showAlert( “Error”, “No value entered” )

elseif tonumber(speedField.text) == nil then

local alert = native.showAlert( “Error”, “Must be a number” )

elseif tonumber(speedField.text) > 100 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

elseif tonumber(speedField.text) < 1 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

else

local myText = display.newText(tonumber (speedField.text) * 2.55, 150, 18, native.systemFont, 16 )

myText.text = (speedField.text) * 2.55

end

end

end

–create the widget

local button = widget.newButton(

{

left = 70,

top = 460,

id = “button”,

label = “Continue”,

onEvent = handleButtonEvent

}

)

–Create function for stop button

local function displayStop()

local StopButton = display.newImage(“stop.png”)

StopButton.x = display.contentCenterX

StopButton.y = display.contentCenterY

StopButton.xScale = 0.5

StopButton.yScale = 0.5

function StopButton:touch (event)

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

print("#CS")

local stopText = display.newText( “Stop”, 160, -10, native.systemFontBold, 18 )

end

return true

end

StopButton:addEventListener(“touch”, StopButton)

end

local myText = display.newText( “”, 160, -10, native.systemFontBold, 18 )

local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code)

local arrow = display.newImage(“arrow.png”)

arrow.x = fullw

arrow.y = fullh

arrow.xScale = centerX

arrow.yScale = centerY

arrow.rotation = rotatione

commande = command

codee = code

function arrow:touch (event) – add the listener

print("#" … command)

myText.text = code

myText:setFillColour( 1, 0, 0)

end

return true

local arrow:addEventListener(“touch”, arrow)

end

local fullh = {160, 230, 260, 230, 160, 90, 60, 90}

local fullw = {140, 170, 240, 310, 340, 310, 240, 170}

local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360}

local command = {“Forward”, “Right Forward”, “Hard Right”, “Right Backward”, “Backward”, “Left Backward”, “Hard Left”, “Left Forward”}

local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF}

for i = 1, #fullh do

addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] )

end

displayStop()

Then this is the code after i add in the extra end

local widget = require( "widget" ) local speedField = native.newTextField( 160, 450 , 150, 30 ) ----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- --function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print ( "Speed = " .. tonumber(speedField.text) \* 2.55 ) if speedField.text == "" then local alert = native.showAlert( "Error", "No value entered" ) elseif tonumber(speedField.text) == nil then local alert = native.showAlert( "Error", "Must be a number" ) elseif tonumber(speedField.text) \> 100 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) elseif tonumber(speedField.text) \< 1 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) else local myText = display.newText(tonumber (speedField.text) \* 2.55, 150, 18, native.systemFont, 16 ) myText.text = (speedField.text) \* 2.55 end end end --create the widget local button = widget.newButton( { left = 70, top = 460, id = "button", label = "Continue", onEvent = handleButtonEvent } ) --Create function for stop button local function displayStop() local StopButton = display.newImage("stop.png") StopButton.x = display.contentCenterX StopButton.y = display.contentCenterY StopButton.xScale = 0.5 StopButton.yScale = 0.5 function StopButton:touch (event) if ( event.phase == "ended" ) then print("#CS") local stopText = display.newText( "Stop", 160, -10, native.systemFontBold, 18 ) end return true end StopButton:addEventListener("touch", StopButton) end local myText = display.newText( "", 160, -10, native.systemFontBold, 18 ) local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code) local arrow = display.newImage("arrow.png") arrow.x = fullw arrow.y = fullh arrow.xScale = centerX arrow.yScale = centerY arrow.rotation = rotatione commande = command codee = code function arrow:touch (event) -- add the listener print("#" .. command) myText.text = code myText:setFillColour( 1, 0, 0) end return true end arrow:addEventListener("touch", arrow) end local fullh = {160, 230, 260, 230, 160, 90, 60, 90} local fullw = {140, 170, 240, 310, 340, 310, 240, 170} local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360} local command = {"Forward", "Right Forward", "Hard Right", "Right Backward", "Backward", "Left Backward", "Hard Left", "Left Forward"} local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF} for i = 1, #fullh do addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] ) end displayStop()

Sorry i don’t know why the first code wasn’t formatted properly but you get what i mean

local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code) local arrow = display.newImage("arrow.png") arrow.x = fullw arrow.y = fullh arrow.xScale = centerX arrow.yScale = centerY arrow.rotation = rotatione commande = command codee = code function arrow:touch (event) -- add the listener print("#" .. command) myText.text = code myText:setFillColour( 1, 0, 0) end --\<------- what is this supposed to end? Looks like an if statement may have been removed return true end arrow:addEventListener("touch", arrow) end

You have too many "end"s in this block.  It looks like you may have had an if event.phase == “began” then line in your code that got removed. Since this is a touch handler, most people will test for the event phase.  

Rob

  1. Format code posts in the future.

formatyourcode.jpg

  1. The error tells you the line, so the problem is on that line or before it, probably this:

    codee = code – may actually be fine, but probably not what you meant

You have not variable codee…

or line 69:

local function arrows:touch (event) -- (Eagle-eye) Rob has it correct below...

Try commenting out the whole function and see if the problem goes away.

Tip: When you have a problem that is hard to track down, you can

  1. comment out the whole file

  2. slow un-comment in one line at time or one function at a time

Re-load each time.  This will help narrow in on the issue.

PS - Welcome the community, sorry to be short on the first draft of this post.

Hi and welcome to the forums!

You will find more help if you follow a few basic guidelines. First, when posting code, please use the blue <> button in the row with Bold and Italic. Paste your code into the window that pops up. This will format your code making it much easier to read.

Next provide as much information as you can. In this case you have an error saying the problem is in line 69. What line is line 69? Most text editors provide a way to show line numbers making it easy to find. I’m guessing it’s this line:

local function arrows:touch (event) -- add the listener

When adding functions to objects, like with the : operator, the assumption is that the object already exists, in this case arrows, so making it “local” doesn’t make sense because you’ve already declared “arrows” somewhere else.

Try removing the local.

Rob

Hi,

sorry for the formatting i’ll make sure to know for next time and I’ve made a few changes for general tidy up and i now have a new error that says line 79 end expected to close funtion at line 63, however when a add an end it gives me a new error that says main.lua 81 <eof> expected near end. i have put the before and after code below (let me know if i should be starting  new topic for this)

local widget = require( “widget” )

local speedField = native.newTextField( 160, 450 , 150, 30 )


– main.lua


–function to handle button events

local function handleButtonEvent( event )

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

print ( "Speed = " … tonumber(speedField.text) * 2.55 )

if speedField.text == “” then

local alert = native.showAlert( “Error”, “No value entered” )

elseif tonumber(speedField.text) == nil then

local alert = native.showAlert( “Error”, “Must be a number” )

elseif tonumber(speedField.text) > 100 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

elseif tonumber(speedField.text) < 1 then

local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )

else

local myText = display.newText(tonumber (speedField.text) * 2.55, 150, 18, native.systemFont, 16 )

myText.text = (speedField.text) * 2.55

end

end

end

–create the widget

local button = widget.newButton(

{

left = 70,

top = 460,

id = “button”,

label = “Continue”,

onEvent = handleButtonEvent

}

)

–Create function for stop button

local function displayStop()

local StopButton = display.newImage(“stop.png”)

StopButton.x = display.contentCenterX

StopButton.y = display.contentCenterY

StopButton.xScale = 0.5

StopButton.yScale = 0.5

function StopButton:touch (event)

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

print("#CS")

local stopText = display.newText( “Stop”, 160, -10, native.systemFontBold, 18 )

end

return true

end

StopButton:addEventListener(“touch”, StopButton)

end

local myText = display.newText( “”, 160, -10, native.systemFontBold, 18 )

local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code)

local arrow = display.newImage(“arrow.png”)

arrow.x = fullw

arrow.y = fullh

arrow.xScale = centerX

arrow.yScale = centerY

arrow.rotation = rotatione

commande = command

codee = code

function arrow:touch (event) – add the listener

print("#" … command)

myText.text = code

myText:setFillColour( 1, 0, 0)

end

return true

local arrow:addEventListener(“touch”, arrow)

end

local fullh = {160, 230, 260, 230, 160, 90, 60, 90}

local fullw = {140, 170, 240, 310, 340, 310, 240, 170}

local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}

local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360}

local command = {“Forward”, “Right Forward”, “Hard Right”, “Right Backward”, “Backward”, “Left Backward”, “Hard Left”, “Left Forward”}

local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF}

for i = 1, #fullh do

addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] )

end

displayStop()

Then this is the code after i add in the extra end

local widget = require( "widget" ) local speedField = native.newTextField( 160, 450 , 150, 30 ) ----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- --function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print ( "Speed = " .. tonumber(speedField.text) \* 2.55 ) if speedField.text == "" then local alert = native.showAlert( "Error", "No value entered" ) elseif tonumber(speedField.text) == nil then local alert = native.showAlert( "Error", "Must be a number" ) elseif tonumber(speedField.text) \> 100 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) elseif tonumber(speedField.text) \< 1 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) else local myText = display.newText(tonumber (speedField.text) \* 2.55, 150, 18, native.systemFont, 16 ) myText.text = (speedField.text) \* 2.55 end end end --create the widget local button = widget.newButton( { left = 70, top = 460, id = "button", label = "Continue", onEvent = handleButtonEvent } ) --Create function for stop button local function displayStop() local StopButton = display.newImage("stop.png") StopButton.x = display.contentCenterX StopButton.y = display.contentCenterY StopButton.xScale = 0.5 StopButton.yScale = 0.5 function StopButton:touch (event) if ( event.phase == "ended" ) then print("#CS") local stopText = display.newText( "Stop", 160, -10, native.systemFontBold, 18 ) end return true end StopButton:addEventListener("touch", StopButton) end local myText = display.newText( "", 160, -10, native.systemFontBold, 18 ) local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code) local arrow = display.newImage("arrow.png") arrow.x = fullw arrow.y = fullh arrow.xScale = centerX arrow.yScale = centerY arrow.rotation = rotatione commande = command codee = code function arrow:touch (event) -- add the listener print("#" .. command) myText.text = code myText:setFillColour( 1, 0, 0) end return true end arrow:addEventListener("touch", arrow) end local fullh = {160, 230, 260, 230, 160, 90, 60, 90} local fullw = {140, 170, 240, 310, 340, 310, 240, 170} local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360} local command = {"Forward", "Right Forward", "Hard Right", "Right Backward", "Backward", "Left Backward", "Hard Left", "Left Forward"} local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF} for i = 1, #fullh do addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] ) end displayStop()

Sorry i don’t know why the first code wasn’t formatted properly but you get what i mean

local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code) local arrow = display.newImage("arrow.png") arrow.x = fullw arrow.y = fullh arrow.xScale = centerX arrow.yScale = centerY arrow.rotation = rotatione commande = command codee = code function arrow:touch (event) -- add the listener print("#" .. command) myText.text = code myText:setFillColour( 1, 0, 0) end --\<------- what is this supposed to end? Looks like an if statement may have been removed return true end arrow:addEventListener("touch", arrow) end

You have too many "end"s in this block.  It looks like you may have had an if event.phase == “began” then line in your code that got removed. Since this is a touch handler, most people will test for the event phase.  

Rob