Syntax Error

Hello all, 

I don’t understand why I keep getting this error message, individually local blackBar and local steelBar work fine, but when I try to run them at the same time I get the error message.

What am I doing wrong?

Appreciate any help, 

Thanks

local blackBar local steelBar blackBar = display.newImageRect("blackBar.png", 60, 7) blackBar.x = 90 blackBar.y = 240 blackBar.rotation=0 physics.addBody( blackBar, "kinematic", { density=1.0, friction=0.3, bounce=1 } ) local function doRectTouch( event ) local touchedObject = event.target if event.phase == "began" then display.getCurrentStage():setFocus( touchedObject ) touchedObject.previousX = touchedObject.x touchedObject.previousY = touchedObject.y print("blackBar touched") elseif event.phase == "moved" then touchedObject.x = ( event.x - event.xStart ) + touchedObject.previousX touchedObject.y = ( event.y - event.yStart ) + touchedObject.previousY print("blackBar moved") elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus(nil) print("blackBar released") end return true end blackBar:addEventListener( "touch", doRectTouch ) local function blackBarTapped( event ) transition.to( blackBar, { rotation=20, delta= true } ) end blackBar:addEventListener( "tap", blackBarTapped ) return true steelBar = display.newImageRect("steelBar.png", 80, 10) steelBar.x = 90 steelBar.y = 240 --40 steelBar.rotation=0 physics.addBody( steelBar, "kinematic", { density=1.0, friction=0.1, bounce=1 } ) local function doRectTouch( event ) local touchedObject = event.target if event.phase == "began" then display.getCurrentStage():setFocus( touchedObject ) touchedObject.previousX = touchedObject.x touchedObject.previousY = touchedObject.y print("steelBar touched")

I don’t know why you’ve posted just a small portion of your code - it’s unrelated to the problem as the line with the issue is clearly line 256. Unless that is all of your code, in which case you haven’t closed the last function properly.

The error you’re getting is saying the file is ending suddenly and Lua is expecting something to close a function soon after the variable mentioned in the error.

Unless that really is your whole file … ???

The error is related to the " return true" line which is completely out of place. When you use return, it must be the very last thing you put in (within that scope). As @horacebury said, the error is caused because Lua expects the function (which isn’t even a function in this case) to end with it. If it appears out of the blue like in here, then it’ll always result in a crash.

But, to what @horacebury said, you really should include line numbers when you post only a sample of your code.  steelBar is mentioned 8 times in the code and if that is all we’ve got to go on, then it isn’t always even clear if the error is within the code you’ve posted.

Thanks both and sorry I’m still trying to get the hang of this.

Thanks again.

I don’t know why you’ve posted just a small portion of your code - it’s unrelated to the problem as the line with the issue is clearly line 256. Unless that is all of your code, in which case you haven’t closed the last function properly.

The error you’re getting is saying the file is ending suddenly and Lua is expecting something to close a function soon after the variable mentioned in the error.

Unless that really is your whole file … ???

The error is related to the " return true" line which is completely out of place. When you use return, it must be the very last thing you put in (within that scope). As @horacebury said, the error is caused because Lua expects the function (which isn’t even a function in this case) to end with it. If it appears out of the blue like in here, then it’ll always result in a crash.

But, to what @horacebury said, you really should include line numbers when you post only a sample of your code.  steelBar is mentioned 8 times in the code and if that is all we’ve got to go on, then it isn’t always even clear if the error is within the code you’ve posted.

Thanks both and sorry I’m still trying to get the hang of this.

Thanks again.