Director ERROR: Failed to execute new( params ) function on 'levelSelection' 1.4

Hiya! Hopefully someone can help me out with this question. I have no idea what happened to cause this. I am a new convert from xcode to corona so please bear with me if this is easily solvable. The app loads fine, but when I hit the start button to go to the levelSelection screen it gives me the error "Director ERROR: Failed to execute new( params ) function on ‘levelSelection’ ". I have no idea why, I ran the debugger and it said there is an issue with line 1093 of the director.lua file. I find it hard to believe since this file has worked before. I scanned the code over and over and still cannot seem to find the issue. Any help would be greatly appreciated.

Here is the code for mainMenu.lua which takes me to the levelSelection screen.

module(..., package.seeall)  
  
function new ()  
 local localGroup = display.newGroup()  
  
  
-------------------  
-- SCENE SET UP --  
-------------------  
  
local background = display.newImage("images/background.png")  
localGroup:insert (background)  
-- inserts background  
  
local startIcon = display.newImage("images/startButton.png")  
startIcon.x = 160  
startIcon.y = 240  
localGroup:insert(startIcon)  
--inserts start icon  
local function gotoLevelSelector (event)  
director:changeScene ("levelSelection")  
end  
startIcon:addEventListener ("touch", gotoLevelSelector)  
--------------------  
--------------------  
  
 return localGroup  
end  

Here is my code for levelSelection.lua

[code]module(…, package.seeall)
function new()
local localGroup = display.newGroup()

require “saveit”

local function resumeStart()
local path = system.pathForFile( “ourdata.txt”, system.DocumentsDirectory )
local file = io.open( path, “r” )

if file then
print(“Loading our data…”)
local contents = file:read( “*a” )

local prevState = explode(", ", contents)

_G.onelock = prevState[1]
_G.twolock = prevState[2]

io.close( file )

else
_G.onelock = 1
_G.twolock = 0
end
end

local function onSystemEvent( event )
if( event.type == “applicationExit” ) then
local path = system.pathForFile( “ourdata.txt”, system.DocumentsDirectory )
local file = io.open( path, “w+b” )

file:write( _G.onelock …", "… _G.twolock)
io.close( file )
end
end
– explode helper function
function explode(div,str)
if (div==’’) then return false end
local pos,arr = 0,{}
– for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) – Attach chars left of current divider
pos = sp + 1 – Jump past current divider
end
table.insert(arr,string.sub(str,pos)) – Attach chars right of last divider
return arr
end

local function init()
– start and resume from previous state, if any
resumeStart()

Runtime:addEventListener( “system”, onSystemEvent )
end

–start the program
init()
–======================
– SET UP SCREEN –
–======================

local background = display.newImage (“images/background.png”)
localGroup:insert(background)
– Sets the background

local leveloneicon = display.newImage (“images/levelbuttongreen1.png”)
leveloneicon.x = 50
leveloneicon.y = 40
localGroup:insert(leveloneicon)
– Sets the icon for level one

local function gotoone (event)
director:changeScene(“level1”)
end
leveloneicon:addEventListener(“tap”, gotoone)
– Go to level one when icon is tapped

local function gototwo (event)
director:changeScene(“level2”)
end
– Function to go to level two

local function seticontwo (event)
if _G.twolock-0 == 0 then
local leveltwoicon = display.newImage (“images/levelbuttongreen1.png”)
leveltwoicon.x = 130
leveltwoicon.y = 40
localGroup:insert(leveltwoicon)
elseif _G.twolock-0 == 1 then
local leveltwoicon = display.newImage (“images/levelbuttongreen.png”)
leveltwoicon.x = 130
leveltwoicon.y = 40
localGroup:insert(leveltwoicon)
leveltwoicon:addEventListener(“tap”, gototwo)
end
end
seticontwo()

return localGroup
end[/code] [import]uid: 86909 topic_id: 15784 reply_id: 315784[/import]

Hello Huffman,
I am a newbie too. I have come across the same error several times. the terminal showed the error in some 1*** line of the director. I tried to figure out what it was. But soon realized that error was being shown because some images in that screen (levelSelection in your case) were not being loaded properly. Check whether you have given the right path and the right name of your image. Also whether that image format is supported by corona.If it works check whether it works on the device. Because now my app doesn’t work on device although it works perfectly on the simulator. I get the same director error notification on my iPhone when i try to load a particular screen. Remember I am not as good as people out there. so don’t blame me if this doesn’t work.
Have a nice day :slight_smile: [import]uid: 76873 topic_id: 15784 reply_id: 59019[/import]

I have had the same issue when loading the “menu.lua” file from the “main.lua” file. It appears to load fine, but the changeScene does not work within the menu.lua file. Does anyone know why this happens? [import]uid: 38000 topic_id: 15784 reply_id: 59225[/import]

Does it throw an error…? that could happen sometimes if it could not load the image or some small syntax error in your .lua file… [import]uid: 76873 topic_id: 15784 reply_id: 59440[/import]

No, there was no debug info other than the error in the director.lua file
Just yesterday I went through my code line by line and found that one image wasn’t loading properly, which caused the name to produce an error when I tried to add it to the displayGroup. One other thing I found that helps while I was looking in the forums is to change the “showDebug” boolean on the line 60 or so of the director.lua file to true to make Director print better debug feedback.
Hope this helps anyone else that has this issue.
[import]uid: 38000 topic_id: 15784 reply_id: 59587[/import]

@peter9221, I’m wondering what version of Director you might be using. Version 1.4 provides better error message (without needing to change/edit the director.lua file), and should tell you what line of code is causing a problem if the problem is related to finding/loading an image. [import]uid: 67217 topic_id: 15784 reply_id: 59593[/import]

@ask:
I was using director 1.4, and I was using the showDebug=true to help find the issue. It showed an error with the localGroup:insert code, but didn’t say anything else. However, when I looked closely at the image code, in the path for the file I had capitalized one letter that shouldn’t have been capitalized,so it didn’t load, but I missed the image file not loading because it was small and hidden. But because it didn’t load, the localGroup:insert could not find that variable adn produced an error. So, in the end, it was just a small typo on my part. Anyways, thank you for all your help and concern. [import]uid: 38000 topic_id: 15784 reply_id: 59623[/import]

@peter9221, I’m glad to hear you were able to sort it out. I was a bit baffled that you needed to set the showDebug=true – and then I just looked at my director.lua file, and indeed, mine is also set showDebug=true. I must’ve done it the moment I got a hold of Director v1.4 but forgot that I did it and never thought about it again. [import]uid: 67217 topic_id: 15784 reply_id: 59625[/import]