Corona SDK Error: “ ?:0:table index is nil ” when I try to go to a new scene

I am getting an error saying ?:0: table index is nil
stack traceback:
C: in function ‘error’
?: in function ‘gotoScene’

The error is coming from the startpressed function in my code, though
I think there is something wrong with my selectlevel.lua file.

Here is my code for menu.lua:

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

local bg
local startb
local aboutb
local title

local function startpressed(event)
if (event.phase == “ended”) then
print(“Works”)
storyboard.gotoScene(“selectlevel”)
end

end

local function aboutpressed(event)
if (event.phase == “ended”) then
print(“Works!”)
–storyboard.gotoScene(“selectlevel”)
end

end

function scene:createScene( event )
local group = self.view
bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
startb = display.newImage(“startbutton.png”)
aboutb = display.newImage(“aboutbutton.png”)
title = display.newText(“Bouncy Shooter”, 100, 200,Batang, 75)
title:setFillColor( 0, 0, 0 )
end

function scene:enterScene( event )
local group = self.view
print(“entered”)
group:insert(bg)
group:insert(startb)

bg.x = display.contentWidth/2
bg.y = display.contentHeight/2

startb.x = display.contentWidth/2
startb.y = display.contentHeight/2 - startb.contentHeight/2

aboutb.x = display.contentWidth/2
aboutb.y = display.contentHeight/2 + aboutb.contentHeight/1.5

title.x = display.contentWidth/2
title.y = 0 + title.contentHeight

startb:addEventListener(“touch”, startpressed)
aboutb:addEventListener(“touch”, aboutpressed)

end

function scene:exitScene(event)
local group = self.view
startb:removeEventListener(“touch”, startpressed)
aboutb:removeEventListener(“touch”, aboutpressed)

end

function scene:destroyScene(event)

end

scene:addEventListener( “createScene”, scene )

scene:addEventListener( “enterScene”, scene )

scene:addEventListener( “exitScene”, scene )

scene:addEventListener( “destroyScene”, scene )

return scene

Here is my code for selectlevel.lua:

local storyboard = require( “storyboard” )
local scene = storyboard.newScene()

local box1
local box2
local notdone

function scene:createScene(event)
local group = self.view
box1 = display.newImage(“level1button.png”)
box2 = display.newImage(“level2button.png”)

end

function scene:enterScene(event)
local group = self.view
box1.x = display.contentWidth/10 + box1.contentWidth
box1.y = display.contentHeight/10 + box1.contentHeight

box2.x = box1.x + box2.contentWidth * 1.5
box2.y = box1.y
group:insert(box1)
group:inset(box2)

end

function scene:exitScene(event)
local group = self.view

end

function scene:destroyScene(event)
local group = self.view

end

scene:addEventListener(createScene, scene)

scene:addEventListener(enterScene, scene)

scene:addEventListener(exitScene, scene)

scene:addEventListener(destroyScene, scene)

return scene

As you can probably tell, I am new at Corona, so please don’t make fun.

 

Can you try inserting your box1 and box2 objects into the scene group in createScene instead of enterSene?

Still doesn’t work

there are two mistakes

1.group:inset(box2) -> group:insert(box2)

2.you forgot to add “” in your scene:addEventListener

right: scene:addEventListener( “createScene”, scene )

wrong" scene:addEventListener( createScene, scene )

this is why your application shows error

I finally figured it out. I didn’t put quotes around the “createScene”, “enterScene”, etc in selectlevel.lua.

Can you try inserting your box1 and box2 objects into the scene group in createScene instead of enterSene?

Still doesn’t work

there are two mistakes

1.group:inset(box2) -> group:insert(box2)

2.you forgot to add “” in your scene:addEventListener

right: scene:addEventListener( “createScene”, scene )

wrong" scene:addEventListener( createScene, scene )

this is why your application shows error

I finally figured it out. I didn’t put quotes around the “createScene”, “enterScene”, etc in selectlevel.lua.