Hello again everyone. I am eleven years old and a novice at Corona. I have a large amount of code for creating an invisible explosion. However, after adding the final event listener, terminal says that it is trying to call method "getOrCreateTable" and says it is a nil value. Oddly, I never included tables in my code. It does the strack traceback thing and says
[C]: in function 'getOrCreateTable'
?: in function 'addEventListener'
One thing to note is that when I replace 'background' in the final event listener with 'Runtime', it replaces all instances of 'getOrCreateTable' with 'respondsToEvent'. Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | local physics = require("physics") physics.start() physics.setScale(40) display.setStatusBar( display.HiddenStatusBar ) local background = display.newImage( "background.png", 0, 0, true ) background.x = display.contentWidth / 2 background.y = display.contentHeight / 2 local floor = display.newImage( "floor.png", 0, 280, true ) physics.addBody( floor, "static", { friction = 0.5 } ) local function onLocalCollision( self, event ) if ( event.phase == "began" and self.myName == "circle" ) then local forcex = event.other.x-self.x local forcey = event.other.y-self.y-20 if (forcex < 0) then forcex = 0-(80+forcex)-12 else forcex = 80-forcex+12 end event.other:applyForce( forcex, forcey, self.x, self.y ) end end local crates = {} for i = 1, 5 do for j = 1, 5 do crates[i] = display.newImage( "crate.png", 140 + (i*50), 220 - (j*50) ) physics.addBody( crates[i], { density = 0.2, friction = 0.1, bounce = 0.1 } ) end end local circle = "" local function setBomb ( event ) if(event.phase == "began") then circle = display.newCircle( event.x, event.y, 80 ) circle.myName = "circle" circle.setFillColor( 0, 0, 0, 0 ) physics.addBody( circle, "static", {isSensor = true} ) circle.collision = onLocalCollision circle.addEventListener( "collision", circle ) end if(event.phase == "ended") then circle.removeSelf() end end background.addEventListener( "touch", setBomb ) physics.setDrawMode( "hybrid" ) |
Also, I created a small build.settings file that probably has no importance in the matter, but just to be thorough, here's what little code is in it:
1 2 3 4 5 6 7 8 9 10 11 | settings = { orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight" } } } |
Hi try replacing this:
background.addEventListener( "touch", setBomb )
with this:
background:addEventListener( "touch", setBomb )
Let us know!
Thanks a lot. Apparently I did that with a lot of the function calls. Lol. Thanks. ;)