Problem with my game?

On the Corona SDK’s Terminal there’s written this:

[applescript]

Runtime error
/Users/Marco/Desktop/Flying Bird/director.lua:668: attempt to index field ‘?’ (a boolean value)
stack traceback:
[C]: ?
/Users/Marco/Desktop/Flying Bird/director.lua:668: in function ‘loadScene’
/Users/Marco/Desktop/Flying Bird/director.lua:895: in function ‘loadNextScene’
/Users/Marco/Desktop/Flying Bird/director.lua:1070: in function ‘changeScene’
/Users/Marco/Desktop/Flying Bird/levelselect.lua:62: in function
?: in function <?:229>

[/applescript]

What’s the problem? Should I post the code of the leveselect.lua file??? [import]uid: 27760 topic_id: 32897 reply_id: 332897[/import]

Would have to see code, specifically line 62 in levelselect.lua - absolutely zero to go on above. [import]uid: 52491 topic_id: 32897 reply_id: 130729[/import]

Would have to see code, specifically line 62 in levelselect.lua - absolutely zero to go on above. [import]uid: 52491 topic_id: 32897 reply_id: 130729[/import]

Here’s the code:

[code]
module(…, package.seeall)

local director= require “director”

local scene = {}
scene.new = function()
local lg = display.newGroup()
– const
–The number of buttons you want displayed
numlevels = 1
–The number of screens/pages you want to have
numscreens = 1

– vars local
–You don’t need to change these 4 variables
local main_sprt = nil
local bck_shp = nil
local slider = nil
local slider_sprt = nil

–These are the positions for the buttons. It’s basically the x/y positions for the buttons, repeated over and over. Make sure that there are at least as many positions as you have level buttons. Right now there’s 300 something, so you should be good :wink:
local columns = {43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393}

local rows = {30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210}

–This is the function that gets called when a level button is clicked. Use event.target.level to figure out which level to load.
local function gotoLevel(event)
–native.showAlert(“Loading level…”,"This would load level "…event.target.level,{“OK”})
director:changeScene(“level”…event.target.level, “flip”)
end

– main_sprt
main_sprt = display.newGroup()

– menu background
–local bkg=display.newImage(“background.png”)
–bkg:setFillColor(255,255,255)
–main_sprt:insert( bkg )
–lg:insert(bkg)

–local back=display.newImage(“backButton_over.png”)
–back.x=display.contentWidth-440
–back.y=display.contentHeight-300
–local function pressButtonBack(event)
–if event.phase ==“ended” then
–director:changeScene (“menu”, “flip”)
–media.playEventSound(“Pop.aiff”)
–end
–end

–back:addEventListener(“touch”, pressButtonBack)

–main_sprt:insert(back)
–lg:insert(back)

– slider
–you don’t need to change anything with the next 10 lines.
slider = require( “pageslider” )
slider.init()
slider_sprt = slider.getSprite()
main_sprt:insert( slider_sprt )
slider_sprt.x = 20
slider_sprt.y = 55
local slide_sprt = nil
local btn_sprt = nil
local textInfo_tbl = {}
local btnInfo_tbl = {}

–This function is what actually draws the pages and buttons.
for i=1, numscreens do
– slide - create the group that holds all the objects for this slide.
local slide1 = display.newGroup()
local bg = display.newRect(0,0,440,240)
bg.alpha = 0
bg.isHitTestable = true
slide1:insert(bg)
for j=(i*24-24)+1,i*24 do
if (j <= numlevels) then
–This is where each button is created.
–Here is where you would add logic to determine if a level has been previously been completed, score for that level, etc. and change the image for the button.
local image = display.newImage(“btn.png”) – change “level.png” to change what the buttons look like.
–Set the position for the button from the massive arrays above.
image.x = columns[j]
image.y = rows[j]
–This sets the level variable, the one we use to know which button was clicked.
image.level = j
–Adds the event listener for the gotolevel function
image:addEventListener(“tap”,gotoLevel)
–Adds the shadow text first so it appears under the main text
–local text = display.newText(j,columns[j],rows[j],Trebuchet,25)
–text.x,text.y = columns[j],rows[j]-3
–And the main text
local text2 = display.newText(j,columns[j]-1,rows[j]-1,Noteworthy,30)
text2.x,text2.y = columns[j]-1,rows[j]-4
text2:setTextColor(255,255,255)
–Then insert the button and texts into the slide group.
slide1:insert(image)
slide1:insert(text2)
–slide1:insert(text)
end
end
btn_sprt = renderSlideBtn( i )
– slider
slider.addSlide(slide1, btn_sprt)
end
lg:insert(slider.getSprite())
–This is the level select header at the top of the screen.
local header = display.newText(“Level Select”,display.contentWidth/2,30,native.systemFontBold,25)
–Position of the header,
header.x,header.y = display.contentCenterX,30
–And the color of the header
header:setTextColor(255,255,255)
lg:insert(header)

return lg
end
–This function draws the little buttons at the bottom of the screen that show what page you’re on. You can also click the buttons to go to that specific page.
function renderSlideBtn( btnIndex )

local numbtns = numscreens

– btn
local btn_sprt = display.newGroup()
btn_sprt.x = (display.contentCenterX - ((numbtns/2)*20)) + (btnIndex * 20)-32
btn_sprt.y = 250
btn_sprt.id = btnIndex

– on
local btnOn_sprt = display.newImageRect(“page.png”,10,10)
btn_sprt:insert(btnOn_sprt)

– off
local btnOff_sprt = display.newImageRect(“page.png”,10,10)
btnOff_sprt.alpha = 0.5
btn_sprt:insert(btnOff_sprt)
btnOff_sprt.isVisible = false

return btn_sprt

end

return scene

[/code] [import]uid: 27760 topic_id: 32897 reply_id: 130805[/import]

Here’s the code:

[code]
module(…, package.seeall)

local director= require “director”

local scene = {}
scene.new = function()
local lg = display.newGroup()
– const
–The number of buttons you want displayed
numlevels = 1
–The number of screens/pages you want to have
numscreens = 1

– vars local
–You don’t need to change these 4 variables
local main_sprt = nil
local bck_shp = nil
local slider = nil
local slider_sprt = nil

–These are the positions for the buttons. It’s basically the x/y positions for the buttons, repeated over and over. Make sure that there are at least as many positions as you have level buttons. Right now there’s 300 something, so you should be good :wink:
local columns = {43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,
43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393,43,113,183,253,323,393}

local rows = {30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210,
30,30,30,30,30,30,90,90,90,90,90,90,150,150,150,150,150,150,210,210,210,210,210,210}

–This is the function that gets called when a level button is clicked. Use event.target.level to figure out which level to load.
local function gotoLevel(event)
–native.showAlert(“Loading level…”,"This would load level "…event.target.level,{“OK”})
director:changeScene(“level”…event.target.level, “flip”)
end

– main_sprt
main_sprt = display.newGroup()

– menu background
–local bkg=display.newImage(“background.png”)
–bkg:setFillColor(255,255,255)
–main_sprt:insert( bkg )
–lg:insert(bkg)

–local back=display.newImage(“backButton_over.png”)
–back.x=display.contentWidth-440
–back.y=display.contentHeight-300
–local function pressButtonBack(event)
–if event.phase ==“ended” then
–director:changeScene (“menu”, “flip”)
–media.playEventSound(“Pop.aiff”)
–end
–end

–back:addEventListener(“touch”, pressButtonBack)

–main_sprt:insert(back)
–lg:insert(back)

– slider
–you don’t need to change anything with the next 10 lines.
slider = require( “pageslider” )
slider.init()
slider_sprt = slider.getSprite()
main_sprt:insert( slider_sprt )
slider_sprt.x = 20
slider_sprt.y = 55
local slide_sprt = nil
local btn_sprt = nil
local textInfo_tbl = {}
local btnInfo_tbl = {}

–This function is what actually draws the pages and buttons.
for i=1, numscreens do
– slide - create the group that holds all the objects for this slide.
local slide1 = display.newGroup()
local bg = display.newRect(0,0,440,240)
bg.alpha = 0
bg.isHitTestable = true
slide1:insert(bg)
for j=(i*24-24)+1,i*24 do
if (j <= numlevels) then
–This is where each button is created.
–Here is where you would add logic to determine if a level has been previously been completed, score for that level, etc. and change the image for the button.
local image = display.newImage(“btn.png”) – change “level.png” to change what the buttons look like.
–Set the position for the button from the massive arrays above.
image.x = columns[j]
image.y = rows[j]
–This sets the level variable, the one we use to know which button was clicked.
image.level = j
–Adds the event listener for the gotolevel function
image:addEventListener(“tap”,gotoLevel)
–Adds the shadow text first so it appears under the main text
–local text = display.newText(j,columns[j],rows[j],Trebuchet,25)
–text.x,text.y = columns[j],rows[j]-3
–And the main text
local text2 = display.newText(j,columns[j]-1,rows[j]-1,Noteworthy,30)
text2.x,text2.y = columns[j]-1,rows[j]-4
text2:setTextColor(255,255,255)
–Then insert the button and texts into the slide group.
slide1:insert(image)
slide1:insert(text2)
–slide1:insert(text)
end
end
btn_sprt = renderSlideBtn( i )
– slider
slider.addSlide(slide1, btn_sprt)
end
lg:insert(slider.getSprite())
–This is the level select header at the top of the screen.
local header = display.newText(“Level Select”,display.contentWidth/2,30,native.systemFontBold,25)
–Position of the header,
header.x,header.y = display.contentCenterX,30
–And the color of the header
header:setTextColor(255,255,255)
lg:insert(header)

return lg
end
–This function draws the little buttons at the bottom of the screen that show what page you’re on. You can also click the buttons to go to that specific page.
function renderSlideBtn( btnIndex )

local numbtns = numscreens

– btn
local btn_sprt = display.newGroup()
btn_sprt.x = (display.contentCenterX - ((numbtns/2)*20)) + (btnIndex * 20)-32
btn_sprt.y = 250
btn_sprt.id = btnIndex

– on
local btnOn_sprt = display.newImageRect(“page.png”,10,10)
btn_sprt:insert(btnOn_sprt)

– off
local btnOff_sprt = display.newImageRect(“page.png”,10,10)
btnOff_sprt.alpha = 0.5
btn_sprt:insert(btnOff_sprt)
btnOff_sprt.isVisible = false

return btn_sprt

end

return scene

[/code] [import]uid: 27760 topic_id: 32897 reply_id: 130805[/import]

There must be an easier way for you to place those buttons. From the comments, it looks like all those numbers are x,y coordinates for some buttons that are being placed? Why do the numbers repeat so much? [import]uid: 14461 topic_id: 32897 reply_id: 130893[/import]

There must be an easier way for you to place those buttons. From the comments, it looks like all those numbers are x,y coordinates for some buttons that are being placed? Why do the numbers repeat so much? [import]uid: 14461 topic_id: 32897 reply_id: 130893[/import]

Go look up the “print_r” function in the community code and use it to do a:

print_r(event)

inside your gotoLevel() function.

Either event.target is nil or event.target.level is nil.

[import]uid: 19626 topic_id: 32897 reply_id: 130964[/import]

Go look up the “print_r” function in the community code and use it to do a:

print_r(event)

inside your gotoLevel() function.

Either event.target is nil or event.target.level is nil.

[import]uid: 19626 topic_id: 32897 reply_id: 130964[/import]