Runtime Error, Assertion Failed

When trying to simulate my game I get this error

Runtime error

assertion failed!

stack traceback:

C: in function ‘assert’

?: in function ‘getOrCreateTable’

?: in function ‘addEventListener’

?: in function ‘addEventListener’

c:\users\rob and aidans user\desktop\pixels\main.lua:46: in main

I dont know how to fix this problem.

Heres my code:

 – cpmgen main.lua

local sprite = require(“sprite”)

local physics = require(“physics”)

physics.start()

local widgets = require(“widget”)

system.activate(“multitouch”)

display.setStatusBar(display.HiddenStatusBar)

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

background.x = display.contentWidth/2; display.contentHeight = 160;

local groundbottom = display.newImage(“ground.png”)

groundbottom.x = display.contentWidth/2; groundbottom.y = display.contentHeight+150;

groundbottom:setReferencePoint(display.BottomLeftReferencePoint);

physics.addBody( groundbottom, “static”, { friction=0.5, bounce=0.3 } )

guy = display.newImage(“char.png”)

physics.addBody( guy, “dynamic”, { friction=0.5, bounce=0 } )

guy.x = math.random(10,display.contentWidth-10)

local left = display.newImage (“lftbtn.png”)

left.x = 45; left.y = 280;

local right = display.newImage (“rghtbtn.png”)

right.x = 120; right.y = 282;

function left:touch()

motionx = -speed;

guy.xScale = -1

end

left:addEventListener(“touch”,left)

  

function right:touch()

motionx = speed;

guy.xScale = 1

end

right:addEventListener(“touch”,right)

function moveplayer (event)

guy.x = guy.x + motionx;

end

Runtime:addEventListener(“enterFrame”, moveGuy)

function stop (event)

if event.phase ==“ended” then

motionx = 0;

end

end

Runtime:addEventListener(“touch”, stop )

player.x = 440; player.y = 280;

function guy:touch(event)

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

guy:setLinearVelocity( 0, -150 )

end

end

guy:addEventListener(“touch”,guy)

print(system.getInfo(“model”))

function guy:tap( event )

 if (event.numTaps == 2 ) then

 print( “The object was double-tapped.” )

 return true;

 elseif (event.numTaps == 1 ) then

 print(“The object was tapped once.”)

 end

 end

guy:addEventListener( “tap” )

I don’t see a “moveGuy” function that you’re using in the enterFrame listener.

Oh yeah, I copied the code from one of my old games because it seemed to fit in well, but to stop confusion I changed player to guy, and it says movePlayer not moveGuy. Ive fixed that now

I have run into a new problem.

It is normal to get lots of problems?

– cpmgen main.lua

local sprite = require(“sprite”)

local physics = require(“physics”)

physics.start()

local widgets = require(“widget”)

system.activate(“multitouch”)

display.setStatusBar(display.HiddenStatusBar)

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

background.x = display.contentWidth/2; display.contentHeight = 160;

local groundbottom = display.newImage(“ground.png”)

groundbottom.x = display.contentWidth/2; groundbottom.y = display.contentHeight+150;

groundbottom:setReferencePoint(display.BottomLeftReferencePoint);

physics.addBody( groundbottom, “static”, { friction=0.5, bounce=0.3 } )

guy = display.newImage(“char.png”)

physics.addBody( guy, “dynamic”, { friction=0.5, bounce=0 } )

guy.x = math.random(10,display.contentWidth-10)

local left = display.newImage (“lftbtn.png”)

left.x = 45; left.y = 280;

local right = display.newImage (“rghtbtn.png”)

right.x = 120; right.y = 282;

function left:touch()

motionx = -speed;

guy.xScale = -1

end

left:addEventListener(“touch”,left)

  

function right:touch()

motionx = speed;

guy.xScale = 1

end

right:addEventListener(“touch”,right)

local function moveGuy (event)

guy.x = guy.x + motionx;

end

Runtime:addEventListener(“enterFrame”, moveGuy)

local function stop (event)

if event.phase ==“ended” then

motionx = 0;

end

end

Runtime:addEventListener(“touch”, stop )

guy.x = 440; guy.y = 280;

function guy:touch(event)

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

guy:setLinearVelocity( 0, -150 )

end

end

guy:addEventListener(“touch”,guy)

print(system.getInfo(“model”))

function guy:tap( event )

 if (event.numTaps == 2 ) then

 print( “The object was double-tapped.” )

 return true;

 elseif (event.numTaps == 1 ) then

 print(“The object was tapped once.”)

 end

 end

guy:addEventListener( “tap” )

When I run my code above it comes up saying:

corona runtime error

c:\user\rob and aidans user\desktop\pixels\main.lua:44: attempt to

perform arithmetic on global ‘motionx’ (a nil value)

stack traceback:

c:\user\rob and aidans user\desktop\pixels\main.lua:44 in function

<c:\user\rob and aidans user\desktop\pixels\main.lua:43>

?: in function <?:218>

dont worry I’ve fixed it I added: 

motionx = 0; 

 speed = 2; 

I guess that I had to have something that motionx can relate to so the code can work.

Yes, it’s normal to run into problems.  Experience and learning more will help reduce the number of problems you run into.  Probably the biggest thing is learning how to read error messages and translate them to what is broken and knowing what to fix.

I don’t see a “moveGuy” function that you’re using in the enterFrame listener.

Oh yeah, I copied the code from one of my old games because it seemed to fit in well, but to stop confusion I changed player to guy, and it says movePlayer not moveGuy. Ive fixed that now

I have run into a new problem.

It is normal to get lots of problems?

– cpmgen main.lua

local sprite = require(“sprite”)

local physics = require(“physics”)

physics.start()

local widgets = require(“widget”)

system.activate(“multitouch”)

display.setStatusBar(display.HiddenStatusBar)

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

background.x = display.contentWidth/2; display.contentHeight = 160;

local groundbottom = display.newImage(“ground.png”)

groundbottom.x = display.contentWidth/2; groundbottom.y = display.contentHeight+150;

groundbottom:setReferencePoint(display.BottomLeftReferencePoint);

physics.addBody( groundbottom, “static”, { friction=0.5, bounce=0.3 } )

guy = display.newImage(“char.png”)

physics.addBody( guy, “dynamic”, { friction=0.5, bounce=0 } )

guy.x = math.random(10,display.contentWidth-10)

local left = display.newImage (“lftbtn.png”)

left.x = 45; left.y = 280;

local right = display.newImage (“rghtbtn.png”)

right.x = 120; right.y = 282;

function left:touch()

motionx = -speed;

guy.xScale = -1

end

left:addEventListener(“touch”,left)

  

function right:touch()

motionx = speed;

guy.xScale = 1

end

right:addEventListener(“touch”,right)

local function moveGuy (event)

guy.x = guy.x + motionx;

end

Runtime:addEventListener(“enterFrame”, moveGuy)

local function stop (event)

if event.phase ==“ended” then

motionx = 0;

end

end

Runtime:addEventListener(“touch”, stop )

guy.x = 440; guy.y = 280;

function guy:touch(event)

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

guy:setLinearVelocity( 0, -150 )

end

end

guy:addEventListener(“touch”,guy)

print(system.getInfo(“model”))

function guy:tap( event )

 if (event.numTaps == 2 ) then

 print( “The object was double-tapped.” )

 return true;

 elseif (event.numTaps == 1 ) then

 print(“The object was tapped once.”)

 end

 end

guy:addEventListener( “tap” )

When I run my code above it comes up saying:

corona runtime error

c:\user\rob and aidans user\desktop\pixels\main.lua:44: attempt to

perform arithmetic on global ‘motionx’ (a nil value)

stack traceback:

c:\user\rob and aidans user\desktop\pixels\main.lua:44 in function

<c:\user\rob and aidans user\desktop\pixels\main.lua:43>

?: in function <?:218>

dont worry I’ve fixed it I added: 

motionx = 0; 

 speed = 2; 

I guess that I had to have something that motionx can relate to so the code can work.

Yes, it’s normal to run into problems.  Experience and learning more will help reduce the number of problems you run into.  Probably the biggest thing is learning how to read error messages and translate them to what is broken and knowing what to fix.