Can you throw some code up so we can see what you’re working with? [import]uid: 135394 topic_id: 30162 reply_id: 122236[/import]
Sure, here is an example.
function background ()
bkg1 = display.newRect(100,100, 200, 200)
bkg2 = display.newRect(300,300, 50, 50)
return bkg1
return bkg2
end
background ()
If I return both display objects I get an index error. If I break them up into separate functions, that works fine, until I try and load the module using the storyboard api. Any thought? Thanks.
SM
[import]uid: 79586 topic_id: 30162 reply_id: 122312[/import]
If that is the whole code, remember that you have to create the table for the background images, return the table at the end of the code, and not call the function inside of the module. For example, here is what Paul suggested above, and how it can be implemented in a module:
background.lua:
[lua]local B = {}
local function createBackground()
bkg1 = display.newRect(100,100, 200, 200)
bkg2 = display.newRect(300,300, 50, 50)
return bkg1
end
B.createBackground = createBackground
return B[/lua]
scene1.lua:
[lua]function scene:createScene( event )
local group = self.view
local test
test = background.createBackground()
group:insert(test) – will be destroyed when scene changes
end[/lua]
That’s the whole code, and it works like charm. I’m not sure why it works without returning the second object, but it didn’t throw any errors for me. Let me know if the above works for you. [import]uid: 135394 topic_id: 30162 reply_id: 122362[/import]