Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Syntax Error
Started by DLuck Feb 25 2019 08:31 PM

3 replies to this topic
eof

Best Answer XeduR @Spyric , 26 February 2019 - 04:19 AM

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

DLuck

[GLOBAL: userInfoPane.html]
DLuck
  • Enthusiast

  • 68 posts
  • Corona SDK



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")


Attached Files



[TOPIC: post.html]
#2

horacebury

[GLOBAL: userInfoPane.html]
horacebury
  • Corona Geek

  • 3,059 posts
  • Corona SDK

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 ... ???



[TOPIC: post.html]
#3

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 582 posts
  • Corona SDK

  Best Answer

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.


  • DLuck likes this

[TOPIC: post.html]
#4

DLuck

[GLOBAL: userInfoPane.html]
DLuck
  • Enthusiast

  • 68 posts
  • Corona SDK

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

 

Thanks again.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: eof