Count Number Of Objects On The Screen?

I’m trying to see if it’s possible to get all the objects

with the same name. I’m using the following code to load a bunch of
circles on the screen. They all have the same

local myCircle = display.newCircle(30+(yCount\*20), 220+(yCount\*10), 8) myCircle.name = "peg"

I would imagine there is a way to do this but I’m not sure where to even look for such a thing.

Thanks

 

Add each one to a display group, and it’s basically a table where you can get a count using .numChildren property or #group value.

Even if you don’t add them to a group you can get the properties from the display objects (although using a group has advantages, such as you knowing EXACTLY what is available in the group since you put it there).

This code will print the name property of every object it finds at the “root” or stage level of the app.

[lua]

local stage = display.getCurrentStage()

for x = 1, stage.numChildren do

    if stage[x].name then

        print(stage[x].name)

    end

end

[/lua]

Try something like that.

 Jay

Add each one to a display group, and it’s basically a table where you can get a count using .numChildren property or #group value.

Even if you don’t add them to a group you can get the properties from the display objects (although using a group has advantages, such as you knowing EXACTLY what is available in the group since you put it there).

This code will print the name property of every object it finds at the “root” or stage level of the app.

[lua]

local stage = display.getCurrentStage()

for x = 1, stage.numChildren do

    if stage[x].name then

        print(stage[x].name)

    end

end

[/lua]

Try something like that.

 Jay