Maximum number of groups?

Are there any maximum number of groups in corona? apparently my game suddenly doesn’t work after adding some game Objects and LOCAL variables on a seperate Composer. I sudden;y can’t insert an object to my group, or maybe the variable group is not a group. here is ther error code

“Attempt to call method ‘insert’ (a nil value)”

my code is this:

displayGroup = {} displayGroup.gameGroup = display.newGroup() local bg = display.newRect(0,0,100,100) displayGroup.gameGroup:insert(bg)

it’s weird there is no error here.
when I try to skip my main menu, go straight ahead to my Game, there is no error

there are a lot scenes in between main menu and game

Your problem there isn’t a maximum number of groups, it’s that you’re trying to call a function which doesn’t exit. In this case, the ‘insert()’ function.

You say, “there is no error here” - so where are you seeing the error “Attempt to call method ‘insert’ (a nil value)”? Those two statements conflict. The code you have posted would definitely work on it’s own.

You should take a look at how you are constructing the composer scenes and navigating between them. I strongly suspect that you are not adding display objects to groups as much as you think you are and at some point you’re relying on a group which is no longer there.

I see the error is on the same line where I inserted BG to displayGroup.gameGroup, then insert it into the group, the only thing I did to “displayGroup.gameGroup” is make it a newGroup, that’s it.

Some detail:

  • “adding some game Objects and LOCAL variables on a seperate Composer” - what do you mean by “separate Composer”? I assumed you meant ‘scene’.
  • When can’t you insert an object into your group? I tried your code snippet and it works.
  • If the problem involves navigating between composer scenes and only happens after a scene change, you should post code which shows this.
  • “maybe the variable group is not a group” - if you are referring to the variable called “displayGroup” then no, that is just a table, not a display group. To create a display group you need to call display.newGroup(). Simply calling “displayGroup = {}” will only create a table.

I would advise you to read up on how Lua’s tables work and then read the Corona documentation on the Display Group object:

https://www.lua.org/pil/2.5.html

https://docs.coronalabs.com/api/type/GroupObject/index.html

Your problem there isn’t a maximum number of groups, it’s that you’re trying to call a function which doesn’t exit. In this case, the ‘insert()’ function.

You say, “there is no error here” - so where are you seeing the error “Attempt to call method ‘insert’ (a nil value)”? Those two statements conflict. The code you have posted would definitely work on it’s own.

You should take a look at how you are constructing the composer scenes and navigating between them. I strongly suspect that you are not adding display objects to groups as much as you think you are and at some point you’re relying on a group which is no longer there.

I see the error is on the same line where I inserted BG to displayGroup.gameGroup, then insert it into the group, the only thing I did to “displayGroup.gameGroup” is make it a newGroup, that’s it.

Some detail:

  • “adding some game Objects and LOCAL variables on a seperate Composer” - what do you mean by “separate Composer”? I assumed you meant ‘scene’.
  • When can’t you insert an object into your group? I tried your code snippet and it works.
  • If the problem involves navigating between composer scenes and only happens after a scene change, you should post code which shows this.
  • “maybe the variable group is not a group” - if you are referring to the variable called “displayGroup” then no, that is just a table, not a display group. To create a display group you need to call display.newGroup(). Simply calling “displayGroup = {}” will only create a table.

I would advise you to read up on how Lua’s tables work and then read the Corona documentation on the Display Group object:

https://www.lua.org/pil/2.5.html

https://docs.coronalabs.com/api/type/GroupObject/index.html