Basic Group question

Im missing something fundamental…

My understanding of groups is that you might have a group for ‘this area’ , and another for ‘this set of buttons’ and so on.

Add things to the group, then insert the groups to the scene.

I trie this, but cannot insert into the Group:

local sqGroup = display.newGroup

local aSquare = display.newRect(xx *10,xx*10,10,10)

aSquare:setFillColor( 100,0,200)

sqGroup:insert(aSquare)

That fails on the insert line

But if I insert directly to the scene, it works.

local aSquare = display.newRect(xx *10,xx*10,10,10)

aSquare:setFillColor( 100,0,200)

sceneGroup:insert(aSquare)   --sceneGroup is the scene used by composer

Do I misunderstand groups, or do I need to initialise the group in some way to use it?

  

  1. Please format your code posts. formatyourcode.jpg
     

  2. Do you mean this?

    local sqGroup = display.newGroup() – you didn’t call the function local aSquare = display.newRect( sqGroup , xx *10,xx*10,10,10) aSquare:setFillColor( 100,0,200)

 
– This is wrong: local sqGroup = display.newGroup

Please format your code posts.

Sure. Looked for that but didnt spot it. 

display.newGroup() – you didn’t call the function

Great. That will be it. Surprised there was no error on that line. What does newGroup  without the brackets actually do then?

It returned an non-nil object of some kind.

This just returns the function as a value itself, i.e. you assigned the newGroup function to you sqGroup variable and then you could’ve used it like this.

[lua]

local myGroup = sqGroup()

[/lua]

Ah of course.

A pointer to function.

  1. Please format your code posts. formatyourcode.jpg
     

  2. Do you mean this?

    local sqGroup = display.newGroup() – you didn’t call the function local aSquare = display.newRect( sqGroup , xx *10,xx*10,10,10) aSquare:setFillColor( 100,0,200)

 
– This is wrong: local sqGroup = display.newGroup

Please format your code posts.

Sure. Looked for that but didnt spot it. 

display.newGroup() – you didn’t call the function

Great. That will be it. Surprised there was no error on that line. What does newGroup  without the brackets actually do then?

It returned an non-nil object of some kind.

This just returns the function as a value itself, i.e. you assigned the newGroup function to you sqGroup variable and then you could’ve used it like this.

[lua]

local myGroup = sqGroup()

[/lua]

Ah of course.

A pointer to function.