Problem with Display Groups

I’m having a bit of a mare here trying to use display groups.
Near the top of my code I’m creating various display groups like thus:
[lua]arena_base = display.newGroup – base of arena (floor, wall etc.)
entities = display.newGroup – food, critter, bombs, enemies etc.
flashystuff = display.newGroup – Particles, explosions etc.
gametext = display.newGroup – Any text to be displayed
arena_top = display.newGroup – Anything that needs to be on top.[/lua]

When the user has clicked the start button it calls the initgame function in which all of the game variables are set up, but when I get to this bit…
[lua]background = display.newImage(“gfx/arena1.png”)
arena_base:insert(background) – Insert into the arena_base display group[/lua]
I get the following error in the terminal
[bash]Runtime error
/Users/home/Desktop/coroner/main.lua:30: attempt to index global ‘arena_base’ (a function value)
stack traceback:
[C]: ?
/Users/home/Desktop/coroner/main.lua:30: in function ‘initGame’
/Users/home/Desktop/coroner/main.lua:20: in function
?: in function <?:214>
[/bash]

Anyone got any ideas what I’m doing wrong?

[EDIT]
Ignore me. I’ve just realised that after days of struggling with this it’s as simple as missing the brackets from the end of the display.newGroup() command. DOH!

Feel free to go about your business, there’s nothing to see here.
:slight_smile: [import]uid: 7841 topic_id: 14367 reply_id: 314367[/import]

when you create new groups, you have to invoke the function to get an object, what you have/are doing is assigning it a function.

in simpler language,

[lua]arena_base = display.newGroup
arena_base_object = arena_base()
background = display.newImage(“gfx/arena1.png”)
arena_base_object:insert(background)[/lua]

did you get the difference between setting and omitting the () ?

another simpler example for you to understand this just in case is
[lua]local myP = print

myP(“Hello World”)
myP(“We can print using both”)
myP(“the myP function”)
print(“and the print function”)
print(“cool, and confusing”)[/lua]

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 14367 reply_id: 53076[/import]

Right, yeah, that makes sense. I just can’t believe it took me so long to spot the mistake. Cheers :slight_smile: [import]uid: 7841 topic_id: 14367 reply_id: 53077[/import]