>> Error message: “attempt to call method ‘insert’ (a nil value)”
I have a module ‘m’ that inserts a bunch of objects in to a display group, say, m.view.
This group is then inserted to the main view/group on Storyboard’s enterscene().
All is well, until the scene is exited and re-entered. I get the above error.
It appears m.view is 'nil’ed out on exitScene(), and I am no longer able to use it on enterscene() again.
—
module.lua:
- local m = {}
- m.view = display.newGroup ()
- …
- function m.spawnStuff ()
- – … stuff = a new display object of any kind
- m.view:insert (stuff)
- end
- return m
foobar.lua:
- function scene:enterScene (event)
- local group = self.view
- …
- group:insert (m.view)
- end
The module works perfectly without Storyboard. So my question is, does exitScene() obliterate m.view so that m.spawnStuff() can no longer be used afterwards? What is the best way around this problem, if possible without modifying the module?