Using the Director class without module(...,package.seeall)

Hey all,

the post is pretty self explanatory, trying to do

[lua]local test1 = {}
new = function (params)

test.localGroup = display.newGroup()
local showBack = function()

local back = display.newImage(“back.png”)
test.localGroup:insert(back)
end

test1.showBack = showBack

return test.localGroup
return test1
end[/lua]

obviously doesn’t work, I’m guessing cause it has two returns in the end, but what is the workaround for it.

Thank you for your time. [import]uid: 106739 topic_id: 34068 reply_id: 334068[/import]

Hi,

In lua you can return multiple values:

return test.localGroup, test1  

and calling the function:

local a, b = new(p) [import]uid: 25729 topic_id: 34068 reply_id: 135451[/import]

Ok, so I didn’t get what you meant by “calling the function local a, b = new§”, are you providing a solution with that, or just proving a point? Also, returning both gives me this error:

[lua]director.lua:668: attempt to index field ‘?’ (a boolean value)[/lua]
[import]uid: 106739 topic_id: 34068 reply_id: 135458[/import]

You should only return one display group to Director so thats probably why your getting an error. I use the below in all of my director scenes.

[code]
local M = {}

local function new()
–Setup the display groups we want
local mainGroup = display.newGroup()

–Clean function…
local function clean()
end
M.clean=clean

return mainGroup
end
M.new = new

return M
[/code] [import]uid: 69826 topic_id: 34068 reply_id: 135463[/import]

With this code

test.lua:
[lua]local test = {}
local new = function ()

local testGroup = display.newGroup()
local showBack = function()

local back = display.newImage(“back.png”)
testGroup:insert(back)
end

test.showBack = showBack

return testGroup
end

test.new = new()

return test[/lua]

I get this error

director.lua:1092: attempt to call method 'insert' (a nil value)

and, if it helps, with this main.lua

[lua]local director = require(“director”)

local mainGroup = display.newGroup()

local function main()
mainGroup:insert(director.directorView)
director:changeScene(“test”)

return true
end

main()[/lua] [import]uid: 106739 topic_id: 34068 reply_id: 135633[/import]

Hi, again.

I see that you have difference in you code compared to TandG’s example.
Your code:

 test.new = new() 

TandG’s:

 M.new = new 

Could that be of any help?

(To your earlier post: Yes, I was making a point that you can use multiple return values. Did not realize that you did not actually wanted that in this case…) [import]uid: 25729 topic_id: 34068 reply_id: 135718[/import]

Like Jensto said, try removing the brackets from your “test.new = new” line.
Also remove “test.showBack = showBack”, and just use “showBack()” to call the function.

The only reason i have “M.clean = clean” in mine is because thats the clean function called from director to “clean” timers etc, all the other local functions don’t need to be linked to “test” or “M” in my case.

Apart from that i don’t really see anything that could be causing an issue… The only other thing that we can’t test is the image your actually using for the backBtn. Is it definitely in the base directory and not a subfolder? Or is it maybe a jpg instead? Most of the time when director fails to insert something properly for me its because i accidentally named the image something else! [import]uid: 69826 topic_id: 34068 reply_id: 135729[/import]

Hi,

In lua you can return multiple values:

return test.localGroup, test1  

and calling the function:

local a, b = new(p) [import]uid: 25729 topic_id: 34068 reply_id: 135451[/import]

Ok, so I didn’t get what you meant by “calling the function local a, b = new§”, are you providing a solution with that, or just proving a point? Also, returning both gives me this error:

[lua]director.lua:668: attempt to index field ‘?’ (a boolean value)[/lua]
[import]uid: 106739 topic_id: 34068 reply_id: 135458[/import]

You should only return one display group to Director so thats probably why your getting an error. I use the below in all of my director scenes.

[code]
local M = {}

local function new()
–Setup the display groups we want
local mainGroup = display.newGroup()

–Clean function…
local function clean()
end
M.clean=clean

return mainGroup
end
M.new = new

return M
[/code] [import]uid: 69826 topic_id: 34068 reply_id: 135463[/import]

With this code

test.lua:
[lua]local test = {}
local new = function ()

local testGroup = display.newGroup()
local showBack = function()

local back = display.newImage(“back.png”)
testGroup:insert(back)
end

test.showBack = showBack

return testGroup
end

test.new = new()

return test[/lua]

I get this error

director.lua:1092: attempt to call method 'insert' (a nil value)

and, if it helps, with this main.lua

[lua]local director = require(“director”)

local mainGroup = display.newGroup()

local function main()
mainGroup:insert(director.directorView)
director:changeScene(“test”)

return true
end

main()[/lua] [import]uid: 106739 topic_id: 34068 reply_id: 135633[/import]

Hi, again.

I see that you have difference in you code compared to TandG’s example.
Your code:

 test.new = new() 

TandG’s:

 M.new = new 

Could that be of any help?

(To your earlier post: Yes, I was making a point that you can use multiple return values. Did not realize that you did not actually wanted that in this case…) [import]uid: 25729 topic_id: 34068 reply_id: 135718[/import]

Like Jensto said, try removing the brackets from your “test.new = new” line.
Also remove “test.showBack = showBack”, and just use “showBack()” to call the function.

The only reason i have “M.clean = clean” in mine is because thats the clean function called from director to “clean” timers etc, all the other local functions don’t need to be linked to “test” or “M” in my case.

Apart from that i don’t really see anything that could be causing an issue… The only other thing that we can’t test is the image your actually using for the backBtn. Is it definitely in the base directory and not a subfolder? Or is it maybe a jpg instead? Most of the time when director fails to insert something properly for me its because i accidentally named the image something else! [import]uid: 69826 topic_id: 34068 reply_id: 135729[/import]

Okay, so after changing my code to this

[lua]local M = {}
local new = function ()

local testGroup = display.newGroup()
local showBack = function()

local back = display.newImage(“back.png”)
M:insert(back)
end

local function clean()
end

M.clean = clean

showBack()

return testGroup
end

M.new = new

return M[/lua]

I get this error

[code]
Director ERROR: Failed to execute new( params ) function on ‘test’.

test.lua:15: attempt to call method ‘insert’ (a nil value)
[/code] so obviously I am still getting *something* wrong, I just dont know what! [import]uid: 106739 topic_id: 34068 reply_id: 137893[/import]

You’ve inserted your “back” button into M, which is a table and therefore its breaking. You should be inserting “back” into testGroup as that is your display group. [import]uid: 69826 topic_id: 34068 reply_id: 137895[/import]

whoops, went on a change-everything-to-M spree there. Sorry bout that, and thanks, it works now! [import]uid: 106739 topic_id: 34068 reply_id: 137898[/import]

Okay, so after changing my code to this

[lua]local M = {}
local new = function ()

local testGroup = display.newGroup()
local showBack = function()

local back = display.newImage(“back.png”)
M:insert(back)
end

local function clean()
end

M.clean = clean

showBack()

return testGroup
end

M.new = new

return M[/lua]

I get this error

[code]
Director ERROR: Failed to execute new( params ) function on ‘test’.

test.lua:15: attempt to call method ‘insert’ (a nil value)
[/code] so obviously I am still getting *something* wrong, I just dont know what! [import]uid: 106739 topic_id: 34068 reply_id: 137893[/import]

You’ve inserted your “back” button into M, which is a table and therefore its breaking. You should be inserting “back” into testGroup as that is your display group. [import]uid: 69826 topic_id: 34068 reply_id: 137895[/import]

whoops, went on a change-everything-to-M spree there. Sorry bout that, and thanks, it works now! [import]uid: 106739 topic_id: 34068 reply_id: 137898[/import]

Hi Guys

Is anyone knows if the Director.lua module also need to be modified for to work the way above explained?

And if it is can someone post me a modified version of the Director.lua without the “module(…,package.seeall)”

thanks [import]uid: 115578 topic_id: 34068 reply_id: 142635[/import]