director scenes without using module(..., package.seeall)

I’ve been following the discussion sparked by Jonathan Beebee’s posts on how to more effectively use external files and modular classes. In the comments thread of the first tutorial, Ricardo Rauber suggests:

A quick workaround to use Director:  
  
– scene.lua  
  
local scene = {}  
scene.new = function( params )  
  
— your code here  
  
end  
return scene  

I’ve tried to use the above suggestion by simply modifying the screen1.lua file in Ricardo’s App sample code that you downloaded with the latest .zip file of director.

The problem is that I can’t get it to work. I keep getting a director-generated error that I have "failed to load module screen1…’ Here is how I modified the beginning of the file:
[lua]local screen1 = {}
local screen1_mt = { __index = screen1}|
screen1.new = function ( params )[/lua]
and at the end of the file, I wrote the following:
[lua]return screen1[/lua]
I left the “return localGroup” code intact in the screen1.new function. Has anyone had any success getting this new method to work well with Director? [import]uid: 19999 topic_id: 15975 reply_id: 315975[/import]

I guess you have had some misunderstanding on metatables and the __index method. Have a look at these articles

here and here to see an example of __index functions and how to handle it.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15975 reply_id: 59231[/import]

http://developer.anscamobile.com/forum/2011/09/07/modified-director-jonathan-beebes-blog-post

Take a look at that thread. Someone posted a modified version of director that works without packageseeall. [import]uid: 67839 topic_id: 15975 reply_id: 59251[/import]

thanks for this, elbowroomapps. The modified version of director makes this work as expected. [import]uid: 19999 topic_id: 15975 reply_id: 59364[/import]

The link above is no longer valid. Anyone have a new link or copy of the director class that does not use modules?

Thanks [import]uid: 136162 topic_id: 15975 reply_id: 95333[/import]

This is what I’m using.

scene1.lua

[code]
local scene1 = {}
local localGroup = nil

function scene1.new()
localGroup = display.newGroup()
– add elements to localGroup

return localGroup
end

return scene1
[/code] [import]uid: 58455 topic_id: 15975 reply_id: 95796[/import]