attempt to index upvalue error

I am using the following code to run this simple game. It runs as expected the first time when I run it. However, when the game is restarted, at onCollision, it outputs the following error

main.lua: 207: attempt to index upvalue ‘happy’ a nil value

the code is provided below:

[lua]

-- -- a simple game to learn -- --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- hidding the status bar display.setStatusBar(display.HiddenStatusBar) --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- common variables centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight -------------- forward refs local gameTitle local myPic local score = 0 local goodie local createPlayScreen local startGame local GameOn ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- loading sound volumes local startGameSound = audio.loadSound("sound/startTrack.mp3") local tahaRunSound = audio.loadSound("sound/zoom.wav") ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function createPlayScreen() local background = display.newImage("background.png") background.width = screenWidth background.height= screenHeight background:scale (1.4,1.4) background.x = centerX background.y = centerY -- audio.play(startGameSound) --audio.play( startGameSound, { loops=-1 } ) local backgroundMusicChannel = audio.play( startGameSound, { loops=-1 } ) myPic = display.newImage( "happy.png") myPic:scale (1,1) myPic.x = centerX myPic.y = centerY + 60 transition.to( background, { time=4000, alpha=1, xScale = 1, yScale =1} ) local function showTitle() gameTitle = display.newImage("gametitle.png") gameTitle.x = centerX gameTitle.y = screenTop +90 gameTitle:scale (1,1) gameTitle.alpha = 0 gameTitle:scale(4, 4) scoreTxt = display.newText( "0", 0, 0, "Arial", 400 ) scoreTxt.x = centerX scoreTxt.y = centerY scoreTxt.alpha = 0.5 scoreTxt: setTextColor (0.56, 0.56, 0.56) transition.to( gameTitle, {time=500, alpha=1, xScale=3, yScale=3} ) startGame() end transition.to( myPic, { time=2000, alpha=1, xScale = 3, yScale =3, rotation = 360, y=centerY, onComplete=showTitle } ) end function startGame() local text = display.newText( "Tap me to start", 0, 0, "Arial", 60 ) text.x = centerX text.y = display.contentHeight -30 text:setTextColor(230, 250, 12) local function goAway(event) display.remove(event.target) audio.stop( ) display.remove(myPic) display.remove(gameTitle) display.remove( text ) GameOn() text = nil return true end function fancy() transition.to ( myPic, {time = 1000, xScale = 5, yScale =5, onComplete = goAway} ) end myPic:addEventListener ( "tap", fancy ) end function GameOn() local physics = require "physics" physics.start() physics.setGravity(0,0) -- SETUP GRAPHICS background = display.newImage("background.png") background.alpha = 0 --background: scale (screenWidth,screenHeight) local happy = display.newImage("happy.png") background.width = screenWidth background.height= screenHeight happy.x = screenTop + 80 happy.y = screenLeft + 80 physics.addBody(happy, "dynamic") happy:scale(2,2) happy.type = "player" local angry = display.newImage("rat.png") angry.x = centerX angry.y = centerY --angry: scale(0.5,0.5) physics.addBody(angry, "static") angry.type = "bad" local angry2 = display.newImage("dragon.png") angry2.x = centerX angry2.y = centerY --angry2: scale(0.5,0.5) physics.addBody(angry2, "static") angry2.type = "bad" local angry3 = display.newImage("dog.png") angry3.x = centerX angry3.y = centerY --angry3: scale(0.5,0.5) physics.addBody(angry3, "static") angry3.type = "bad" local angry4 = display.newImage("bear.png") angry4.x = centerX angry4.y = centerY --angry4: scale(0.5,0.5) physics.addBody(angry4, "static") angry4.type = "bad" local angry5 = display.newImage("monkey.png") angry5.x = centerX angry5.y = centerY angry5: scale(0.5,0.5) physics.addBody(angry5, "static") angry5.type = "bad" local function touchScreen(event) if event.phase == "ended" then transition.to(happy,{time=300, x=event.x, y=event.y}) end -- audio.play(mySnd) end Runtime:addEventListener("touch", touchScreen) local function createGoodies() local goodiePics = {"eyecandy\_1.png","eyecandy\_2.png", "eyecandy\_3.png", "eyecandy\_4.png"} goodie = display.newImage(goodiePics[math.random (#goodiePics)]) goodie.x=math.random(120,screenWidth-100) goodie.y=math.random(120,screenHeight-100) goodie: scale(3,3) physics.addBody(goodie, "static") goodie.type = "goodie" end createGoodies() -- CREATE ANGRY MOVEMENT local function moveAngry() transition.to(angry,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight), onComplete=moveAngry}) transition.to(angry2,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry3,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry4,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry5,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) end moveAngry() -- RESPOND TO COLLISIONS local function gameOverAndReset () local text2 = display.newText( "Your Scored " .. score .. " Tap to restart", 0, 0, "Arial",50 ) text2.x = centerX text2.y = centerY text2:setTextColor(0.43, 0.82, 0) happy: removeSelf() happy = nil local function reborn() angry:removeSelf() angry= nil angry2:removeSelf() angry2= nil angry3:removeSelf() angry3= nil angry4:removeSelf() angry4= nil angry5:removeSelf() angry5= nil text2:removeSelf() text2 = nil goodie: removeSelf() goodie = nil ------ createPlayScreen() end text2:addEventListener ( "tap", reborn) end local function onCollision( event) local agro = event.object1 local hit = event.object2 if ( event.phase == "began" ) then if (agro.type == "player" and hit.type == "goodie") then print( agro.type .. hit.type) display.remove (goodie) score = score + 1 scoreTxt.text = score timer.performWithDelay ( 100, createGoodies ) -- display.remove (goodie) else scoreTxt.alpha = 0 -- print( agro.type .. hit.type) gameOverAndReset () end end end Runtime:addEventListener("collision", onCollision) end createPlayScreen()

I know that the code is not written to its best, but my focus is to fix the problem with your help

Please help me fixing this problem and kindly provide some explanation so I can understand why I am getting the error.

Thanks in advance.

Shei7141

The variable ‘happy’ is nil. You need to make sure that when the code restarts, ‘happy’ is given a value.

For more help, some line numbers would be useful.

Thanks,

but how would I do that…

when game starts again after text2:addEventListener ( “tap”, reborn)

all the characters get made as expected and they behave as they should, but on collision the error happen… please suggest

It’s because your onCollision listener is being fired for each object in the collision. The first time it fires it clears out the happy object. The second time it fires (on the other object in the collision) happy is already nil.

http://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html#postcollision

I think you need to listen for local collisions - that is, set a collision listener on each object which can be involved in a collision, not globally. You can’t return true from a global collision listener for each object in the collision to cancel the event propagation (as described in the link above.) You can still use the same listener function, but you need to add the listener to each physics object as you create them.

Here is the changes I made to your code to figure this out:

-- -- a simple game to learn -- --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- hidding the status bar display.setStatusBar(display.HiddenStatusBar) --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- common variables centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight -------------- forward refs local gameTitle local myPic local score = 0 local goodie local createPlayScreen local startGame local GameOn ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- loading sound volumes --local startGameSound = audio.loadSound("sound/startTrack.mp3") --local tahaRunSound = audio.loadSound("sound/zoom.wav") ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function createPlayScreen() local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) -- display.newImage("background.png") background.width = screenWidth background.height= screenHeight background:scale (1.4,1.4) background.x = centerX background.y = centerY -- audio.play(startGameSound) --audio.play( startGameSound, { loops=-1 } ) local backgroundMusicChannel = audio.play( startGameSound, { loops=-1 } ) myPic = display.newCircle( 100, 100, 100 ); myPic.fill = {1,0,0} -- display.newImage( "happy.png") myPic:scale (1,1) myPic.x = centerX myPic.y = centerY + 60 transition.to( background, { time=4000, alpha=1, xScale = 1, yScale =1} ) local function showTitle() gameTitle = display.newCircle( 50, 50, 50 ); gameTitle.fill={0,1,0} -- display.newImage("gametitle.png") gameTitle.x = centerX gameTitle.y = screenTop +90 gameTitle:scale (1,1) gameTitle.alpha = 0 gameTitle:scale(4, 4) scoreTxt = display.newText( "0", 0, 0, "Arial", 400 ) scoreTxt.x = centerX scoreTxt.y = centerY scoreTxt.alpha = 0.5 scoreTxt: setTextColor (0.56, 0.56, 0.56) transition.to( gameTitle, {time=500, alpha=1, xScale=3, yScale=3} ) startGame() end transition.to( myPic, { time=2000, alpha=1, xScale = 3, yScale =3, rotation = 360, y=centerY, onComplete=showTitle } ) end function startGame() local text = display.newText( "Tap me to start", 0, 0, "Arial", 60 ) text.x = centerX text.y = display.contentHeight -30 text:setTextColor(230, 250, 12) local function goAway(event) display.remove(event.target) audio.stop( ) display.remove(myPic) display.remove(gameTitle) display.remove( text ) GameOn() text = nil return true end function fancy() transition.to ( myPic, {time = 1000, xScale = 5, yScale =5, onComplete = goAway} ) end myPic:addEventListener ( "tap", fancy ) end function GameOn() print("GameOn") local physics = require "physics" physics.start() physics.setGravity(0,0) -- SETUP GRAPHICS background = display.newCircle( 50, 50, 25 ); background.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- display.newImage("background.png") background.alpha = 0 --background: scale (screenWidth,screenHeight) local happy = display.newCircle( 50, 50, 25 ); happy.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("happy.png") background.width = screenWidth background.height= screenHeight happy.x = screenTop + 80 happy.y = screenLeft + 80 physics.addBody(happy, "dynamic") happy:scale(2,2) happy.type = "player" print("happy == "..tostring(happy)) local angry = display.newCircle( 50, 50, 25 ); angry.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("rat.png") angry.x = centerX angry.y = centerY --angry: scale(0.5,0.5) physics.addBody(angry, "static") angry.type = "bad" local angry2 = display.newCircle( 50, 50, 25 ); angry2.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("dragon.png") angry2.x = centerX angry2.y = centerY --angry2: scale(0.5,0.5) physics.addBody(angry2, "static") angry2.type = "bad" local angry3 = display.newCircle( 50, 50, 25 ); angry3.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("dog.png") angry3.x = centerX angry3.y = centerY --angry3: scale(0.5,0.5) physics.addBody(angry3, "static") angry3.type = "bad" local angry4 = display.newCircle( 50, 50, 25 ); angry4.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("bear.png") angry4.x = centerX angry4.y = centerY --angry4: scale(0.5,0.5) physics.addBody(angry4, "static") angry4.type = "bad" local angry5 = display.newCircle( 50, 50, 25 ); angry5.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("monkey.png") angry5.x = centerX angry5.y = centerY angry5: scale(0.5,0.5) physics.addBody(angry5, "static") angry5.type = "bad" local function touchScreen(event) if event.phase == "ended" then transition.to(happy,{time=300, x=event.x, y=event.y}) end -- audio.play(mySnd) end Runtime:addEventListener("touch", touchScreen) local function createGoodies() local goodiePics = {"eyecandy\_1.png","eyecandy\_2.png", "eyecandy\_3.png", "eyecandy\_4.png"} goodie = display.newCircle(50,50,10); goodie.fill={math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255} -- display.newImage(goodiePics[math.random(1,#goodiePics)]) goodie.x=math.random(120,screenWidth-100) goodie.y=math.random(120,screenHeight-100) goodie: scale(3,3) physics.addBody(goodie, "static") goodie.type = "goodie" end createGoodies() -- CREATE ANGRY MOVEMENT local function moveAngry() transition.to(angry,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight), onComplete=moveAngry}) transition.to(angry2,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry3,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry4,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry5,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) end moveAngry() -- RESPOND TO COLLISIONS local function gameOverAndReset () local text2 = display.newText( "Your Scored " .. score .. " Tap to restart", 0, 0, "Arial",50 ) text2.x = centerX text2.y = centerY text2:setTextColor(0.43, 0.82, 0) print("Resetting. happy == "..tostring(happy)) happy:removeSelf() happy = nil local function reborn() angry:removeSelf() angry= nil angry2:removeSelf() angry2= nil angry3:removeSelf() angry3= nil angry4:removeSelf() angry4= nil angry5:removeSelf() angry5= nil text2:removeSelf() text2 = nil goodie: removeSelf() goodie = nil ------ createPlayScreen() end text2:addEventListener ( "tap", reborn) end local function onCollision( event) local agro = event.object1 local hit = event.object2 print("agro.type: ",agro.type,hit.type) if ( event.phase == "began" ) then if (agro.type == "player" and hit.type == "goodie") then print( agro.type .. hit.type) display.remove (goodie) score = score + 1 scoreTxt.text = score timer.performWithDelay ( 100, createGoodies ) -- display.remove (goodie) else scoreTxt.alpha = 0 -- print( agro.type .. hit.type) gameOverAndReset() end end print("hello") return true end Runtime:addEventListener("collision", onCollision) end createPlayScreen()

Thanks a alot,

 I will give that a go

The variable ‘happy’ is nil. You need to make sure that when the code restarts, ‘happy’ is given a value.

For more help, some line numbers would be useful.

Thanks,

but how would I do that…

when game starts again after text2:addEventListener ( “tap”, reborn)

all the characters get made as expected and they behave as they should, but on collision the error happen… please suggest

It’s because your onCollision listener is being fired for each object in the collision. The first time it fires it clears out the happy object. The second time it fires (on the other object in the collision) happy is already nil.

http://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html#postcollision

I think you need to listen for local collisions - that is, set a collision listener on each object which can be involved in a collision, not globally. You can’t return true from a global collision listener for each object in the collision to cancel the event propagation (as described in the link above.) You can still use the same listener function, but you need to add the listener to each physics object as you create them.

Here is the changes I made to your code to figure this out:

-- -- a simple game to learn -- --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- hidding the status bar display.setStatusBar(display.HiddenStatusBar) --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- common variables centerX = display.contentCenterX centerY = display.contentCenterY screenLeft = display.screenOriginX screenWidth = display.contentWidth - screenLeft \* 2 screenRight = screenLeft + screenWidth screenTop = display.screenOriginY screenHeight = display.contentHeight - screenTop \* 2 screenBottom = screenTop + screenHeight display.contentWidth = screenWidth display.contentHeight = screenHeight -------------- forward refs local gameTitle local myPic local score = 0 local goodie local createPlayScreen local startGame local GameOn ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-- loading sound volumes --local startGameSound = audio.loadSound("sound/startTrack.mp3") --local tahaRunSound = audio.loadSound("sound/zoom.wav") ----~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function createPlayScreen() local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight ) -- display.newImage("background.png") background.width = screenWidth background.height= screenHeight background:scale (1.4,1.4) background.x = centerX background.y = centerY -- audio.play(startGameSound) --audio.play( startGameSound, { loops=-1 } ) local backgroundMusicChannel = audio.play( startGameSound, { loops=-1 } ) myPic = display.newCircle( 100, 100, 100 ); myPic.fill = {1,0,0} -- display.newImage( "happy.png") myPic:scale (1,1) myPic.x = centerX myPic.y = centerY + 60 transition.to( background, { time=4000, alpha=1, xScale = 1, yScale =1} ) local function showTitle() gameTitle = display.newCircle( 50, 50, 50 ); gameTitle.fill={0,1,0} -- display.newImage("gametitle.png") gameTitle.x = centerX gameTitle.y = screenTop +90 gameTitle:scale (1,1) gameTitle.alpha = 0 gameTitle:scale(4, 4) scoreTxt = display.newText( "0", 0, 0, "Arial", 400 ) scoreTxt.x = centerX scoreTxt.y = centerY scoreTxt.alpha = 0.5 scoreTxt: setTextColor (0.56, 0.56, 0.56) transition.to( gameTitle, {time=500, alpha=1, xScale=3, yScale=3} ) startGame() end transition.to( myPic, { time=2000, alpha=1, xScale = 3, yScale =3, rotation = 360, y=centerY, onComplete=showTitle } ) end function startGame() local text = display.newText( "Tap me to start", 0, 0, "Arial", 60 ) text.x = centerX text.y = display.contentHeight -30 text:setTextColor(230, 250, 12) local function goAway(event) display.remove(event.target) audio.stop( ) display.remove(myPic) display.remove(gameTitle) display.remove( text ) GameOn() text = nil return true end function fancy() transition.to ( myPic, {time = 1000, xScale = 5, yScale =5, onComplete = goAway} ) end myPic:addEventListener ( "tap", fancy ) end function GameOn() print("GameOn") local physics = require "physics" physics.start() physics.setGravity(0,0) -- SETUP GRAPHICS background = display.newCircle( 50, 50, 25 ); background.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- display.newImage("background.png") background.alpha = 0 --background: scale (screenWidth,screenHeight) local happy = display.newCircle( 50, 50, 25 ); happy.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("happy.png") background.width = screenWidth background.height= screenHeight happy.x = screenTop + 80 happy.y = screenLeft + 80 physics.addBody(happy, "dynamic") happy:scale(2,2) happy.type = "player" print("happy == "..tostring(happy)) local angry = display.newCircle( 50, 50, 25 ); angry.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("rat.png") angry.x = centerX angry.y = centerY --angry: scale(0.5,0.5) physics.addBody(angry, "static") angry.type = "bad" local angry2 = display.newCircle( 50, 50, 25 ); angry2.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("dragon.png") angry2.x = centerX angry2.y = centerY --angry2: scale(0.5,0.5) physics.addBody(angry2, "static") angry2.type = "bad" local angry3 = display.newCircle( 50, 50, 25 ); angry3.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("dog.png") angry3.x = centerX angry3.y = centerY --angry3: scale(0.5,0.5) physics.addBody(angry3, "static") angry3.type = "bad" local angry4 = display.newCircle( 50, 50, 25 ); angry4.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("bear.png") angry4.x = centerX angry4.y = centerY --angry4: scale(0.5,0.5) physics.addBody(angry4, "static") angry4.type = "bad" local angry5 = display.newCircle( 50, 50, 25 ); angry5.fill={math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255} -- ("monkey.png") angry5.x = centerX angry5.y = centerY angry5: scale(0.5,0.5) physics.addBody(angry5, "static") angry5.type = "bad" local function touchScreen(event) if event.phase == "ended" then transition.to(happy,{time=300, x=event.x, y=event.y}) end -- audio.play(mySnd) end Runtime:addEventListener("touch", touchScreen) local function createGoodies() local goodiePics = {"eyecandy\_1.png","eyecandy\_2.png", "eyecandy\_3.png", "eyecandy\_4.png"} goodie = display.newCircle(50,50,10); goodie.fill={math.random(1,255)/255,math.random(1,255)/255,math.random(1,255)/255} -- display.newImage(goodiePics[math.random(1,#goodiePics)]) goodie.x=math.random(120,screenWidth-100) goodie.y=math.random(120,screenHeight-100) goodie: scale(3,3) physics.addBody(goodie, "static") goodie.type = "goodie" end createGoodies() -- CREATE ANGRY MOVEMENT local function moveAngry() transition.to(angry,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight), onComplete=moveAngry}) transition.to(angry2,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry3,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry4,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) transition.to(angry5,{time=1500, x=math.random(80,screenWidth), y=math.random(60,screenHeight)}) end moveAngry() -- RESPOND TO COLLISIONS local function gameOverAndReset () local text2 = display.newText( "Your Scored " .. score .. " Tap to restart", 0, 0, "Arial",50 ) text2.x = centerX text2.y = centerY text2:setTextColor(0.43, 0.82, 0) print("Resetting. happy == "..tostring(happy)) happy:removeSelf() happy = nil local function reborn() angry:removeSelf() angry= nil angry2:removeSelf() angry2= nil angry3:removeSelf() angry3= nil angry4:removeSelf() angry4= nil angry5:removeSelf() angry5= nil text2:removeSelf() text2 = nil goodie: removeSelf() goodie = nil ------ createPlayScreen() end text2:addEventListener ( "tap", reborn) end local function onCollision( event) local agro = event.object1 local hit = event.object2 print("agro.type: ",agro.type,hit.type) if ( event.phase == "began" ) then if (agro.type == "player" and hit.type == "goodie") then print( agro.type .. hit.type) display.remove (goodie) score = score + 1 scoreTxt.text = score timer.performWithDelay ( 100, createGoodies ) -- display.remove (goodie) else scoreTxt.alpha = 0 -- print( agro.type .. hit.type) gameOverAndReset() end end print("hello") return true end Runtime:addEventListener("collision", onCollision) end createPlayScreen()

Thanks a alot,

 I will give that a go