Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Error: attempt to perform arithmetic on field "startMoveX" (a nil value)
Started by mparvareshnia80 Jul 10 2018 08:05 AM

- - - - -
2 replies to this topic
arithmetic error help corona newbie
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 5 posts
  • Corona SDK

Hello everyone,
I'm pretty new to Corona and as of lately I've been experiencing an error and where ever I looked I was unable to find a solution for it.
So the error is related to the function I used to be able to move objects around and here is the function that I'm talking about:

local function movePlatform(event)
platformTouched = event.target

        if (event.phase == "began") then
                display.getCurrentStage():setFocus( platformTouched )
  audio.play (selectionSound)
  display.remove( rotationalert )
  rotationalert = nil 
platformTouched.startMoveX = platformTouched.x
platformTouched.startMoveY = platformTouched.y

        elseif (event.phase == "moved") then

               -- The line below is the 392th line:

platformTouched.x = (event.x - event.xStart) + platformTouched.startMoveX

platformTouched.y = (event.y - event.yStart) + platformTouched.startMoveY

                elseif event.phase == "ended" or event.phase == "cancelled"  then

                display.getCurrentStage():setFocus( nil )

                 return true

I have also attached a picture of the error as well as a video of when I get the error as I'm not really sure why I get the error.
Another question that I had is about a retry button that I tried to create. Basically, I want the retry button to restart the level, but, I want it to return the images moved to the location that the user set it to. So basically the person playing the game moves the object to a certain location and then starts the game (which applies physics) and then when the person presses the retry button I want the objects to return to the location that the person moved them to.
Here is the code I used for the retry button and I've also attached a video of it. I'm not sure how to return the objects to the location set by the player.

local function retryTapped(obj)

ball.y = 164
ball.x = 164
ball.rotation = 0
--woodenPlank1.rotation = 0
--woodenBox.rotation = 0
-- woodenBox1.rotation = 0

woodenPlank1:addEventListener( "touch", movePlatform )
woodenPlank1:addEventListener( "tap", platformTapped )
woodenBox:addEventListener( "touch", movePlatform2 )
woodenBox1:addEventListener( "touch", movePlatform2 )
weight:addEventListener( "touch", movePlatform2 )

display.remove( backgroundOverlay )
display.remove( overlay )
display.remove( levelBtn )
display.remove( playBtn )
display.remove( reloadBtn )
return true


Every help would be greatly appreciated.

Attached Thumbnails

  • error.png

Attached Files

[TOPIC: post.html]

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,865 posts
  • Corona Staff

Please use code formatting when posting code. The easiest thing to do is to use the blue <> button and paste your code into the popup window. It will make your code much more readable. Also, your error message is pretty straightforward. On line 392 of level02.lua you're trying to do math with startMoveX which doesn't exist or is nil.  We can't tell from your code what line 392 is, so it would be really helpful if you identified the line of code that's being referenced.



[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 625 posts
  • Corona SDK

at the point where you try to do something (mathematical) with variable startMoveX, it does'nt exist or doesn't have a value.

it's a classic case where you need to step through you code to track down the reason.


Also tagged with one or more of these keywords: arithmetic, error, help, corona, newbie