I have my main game.lua file which has another gameplay.lua file.
In gameplay.lua I try to insert objects into mainGroup which was created in game.lua but I get this error:
...vz07_0x4fkl00000gn/T/TemporaryItems/10/gameplay.lua:15: attempt to index global 'mainGroup' (a nil value)
1 2 3 4 5 6 | -- Create and display the HUD createHUD = function() -- Add HUD graphic local theHUDBanner = display.newImageRect ( "HUDHeader.png", 480, 35 ) theHUDBanner.x, theHUDBanner.y = 240, 12 mainGroup:insert(theHUDBanner) |
Is the mainGroup variable persisted across your modules? if not, then it gets the default value of nil and hence this issue.
Well it's defined in game.lua and is global. Doesn't that make it persist across modules?
no its only global to that module
you can pass it to the other module
othermodulefunction(group)
then in other module
function othermodulefunction(arg)
groupfromothermodule = arg
Oh! Okay. Thanks for your help guys!