Director class fails 'insert'

module(..., package.seeall) function new() local localGroup = display.newGroup(); local back = display.newImageRect("images/back.png", \_W, \_H); back:setReferencePoint(display.CenterReferencePoint); back.x = \_W/2; back.y = \_H/2; back.scene = "menu"; localGroup:insert(back); function changeScene(e) if(e.phase == "ended") then dictector:changeScene(e.target.scene); end end back:addEventListener("touch", changeScene); return localGroup; end

\_W = display.contentWidth; \_H = display.contentHeight; local director = require("director"); local mainGroup = display.newGroup(); local function main() mainGroup:insert(director.directorView); director:changeScene("menu"); return true; end main();

module(..., package.seeall) function new() local localGroup = display.newGroup(); local bg = display.newImageRect("images/bg.png", \_W, \_H); bg:setReferencePoint(display.CenterReferencePoint); bg.x = \_W/2; bg.y = \_H/2; local title = display.newImageRect("images/title.png", \_W, 132); title:setReferencePoint(display.CenterReferencePoint); title.x = \_W/2; title.y = title.height; function changeScene(e) if(e.phase == "ended") then director:changeScene(e.target.scene); end end local play\_btn = display.newImageRect("images/play-btn.png", \_W, 75); play\_btn:setReferencePoint(display.CenterReferencePoint); play\_btn.x = \_W/2; play\_btn.y = \_H/2 + play\_btn.height; play\_btn.scene = "game"; local credits\_btn = display.newImageRect("images/credits-btn.png", \_W, 75); credits\_btn:setReferencePoint(display.CenterReferencePoint); credits\_btn.x = \_W/2; credits\_btn.y = \_H/2 + play\_btn.height + credits\_btn.height; credits\_btn.scene = "credits"; localGroup:insert(bg); localGroup:insert(title); localGroup:insert(play\_btn); localGroup:insert(credits\_btn); play\_btn:addEventListener("touch", changeScene); credits\_btn:addEventListener("touch", changeScene); return localGroup; end

for some reason i am getting an error “director.lua:1092: attempt to call method '‘insert’ (a nil value) stack traceback: [c]; in function ‘insert’ director.lua1092; in function ‘changeScene’ main.lua:16 menu.lua:14 ?:in function <?:218>”

 for i = currentStage.numChildren, 1, -1 do ------------------ -- Verify directorId ------------------ if type( currentStage[i].directorId ) == "nil" then currentStage[i].directorId = newScene end ------------------ -- Insert into the NEXT group if it's needed ------------------ if currentStage[i].directorId == newScene and currentStage[i].directorId ~= "main" then nextScreen:insert( currentStage[i] ) end end

You usually get that error when there’s something wrong with your code and it’s not able to load the file. Look through the lua file you’re attempting to change to and double check everything. Put print statements every few lines to see where your code stops.

 for i = currentStage.numChildren, 1, -1 do ------------------ -- Verify directorId ------------------ if type( currentStage[i].directorId ) == "nil" then currentStage[i].directorId = newScene end ------------------ -- Insert into the NEXT group if it's needed ------------------ if currentStage[i].directorId == newScene and currentStage[i].directorId ~= "main" then nextScreen:insert( currentStage[i] ) end end

You usually get that error when there’s something wrong with your code and it’s not able to load the file. Look through the lua file you’re attempting to change to and double check everything. Put print statements every few lines to see where your code stops.

the director thing obfuscates your error messages. It’s better to not use it.

There’s a corona builtin for that now, or write you can write your own scene change functionionality: e.g. see http://developer.coronalabs.com/code/director-class-24-lines-code for that

the director thing obfuscates your error messages. It’s better to not use it.

There’s a corona builtin for that now, or write you can write your own scene change functionionality: e.g. see http://developer.coronalabs.com/code/director-class-24-lines-code for that