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]