Director + External Modules problem

Hi!

In my game I got three screens: mainmenu, levelmenu and myLevel, all switched with director. I also got a level.lua which myLevel requires from.

The problem is that when I start the game I can go to the mainmenu, then the levelmenu and then myLevel. But if I then go from myLevel to the mainmenu, then the levelmenu and then myLevel again I got this error:

bad argument #-2 to 'insert' (Proxy expected, got nil)

What to do?

Oskar

don't have enough details to find what the problem really is...
will be easier if you can post the code here...

you may also check whether you have included all the below items in all the above mentioned files

1
2
3
4
5
module(..., package.seeall)
local localGroup = display.newGroup()
function new()
        return localGroup
end

I get the error when I try to insert the group that I have in the level.lua file, to the localGroup in the myLevel.lua file when I enter the level a second time.

If you can post the relevant code I can fix it for you....

main.lua:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
print();print("<-========================= Program Start =========================->");print()
-- HIDE THE STATUS BAR
display.setStatusBar( display.HiddenStatusBar )
 
 
-- Import director class
local director = require("director")
 
 
  
-- The main group
local mainGroup = display.newGroup()
 
-- The main function
local function main()
        -- Add the group from director class
        mainGroup:insert(director.directorView)
 
        -- Change scene to mainmenu
        director:changeScene("mainmenu", "fade")
        
        return true
end
 
-- Start!"#!"#!"
main()

What is it inside your level.lua file ?

level.lua:

1
2
module(..., package.seeall)
localGroup = display.newGroup()

try this...
create a function in level.lua file which return the group and call the function from your file.
see the code below

level.lua

1
2
3
4
5
6
7
8
module(..., package.seeall)
function new()
  print("in new")
  local localGroup = display.newGroup()
  local txt = display.newText("from level",200,200,nil,25)
  localGroup:insert(txt)
  return localGroup
end

I get this error when I try it:

Runtime error
/Users/Username/Desktop/myLevel.lua:6: attempt to index global 'localGroup' (a nil value)

I almost, almost, almost got it fixed now.

Just one little problem:

The old problem is gone (which is great! :D ) but now when i enter the myLevel a second time and have a function at the end which sets some layers toFront() i get a new error:

attempt to call method 'toFront' (a nil value)

Note: This only when I already have entered myLevel, gone to the mainmenu, levelmenu and then tries to get back to the myLevel again. It works if i delete the toFront() function.

Can you post the code please ?

Fixed it by making the function at the end a local function instead of a global function.

Thanks for all your help with the other things and sorry for being late with posting code.

views:1510 update:2011/10/12 18:33:00
corona forums © 2003-2011