special table how to access this element ?

hi,

I got this snippet of code but I do not know how to access a specific player…

thanks, for your help.

local player={} for i = 1, 5 do local players=display.newGroup() players.body = display.newCircle(players,0,0,10) players.head=display.newCircle(players,0,-20,5) players.x = 100 + (i-1) \* 15 players.y = 200 player[i] = players end player[2]:setFillColor(1,0,0) doesn't work...

Does player[2].body:setFillColor(1,0,0) work?

thomas6 solution is correct for your problem.

another approach to creating body/head is doing a function to create the body and head with parameters. that way is easier to create more players.

i’ve made a small code to show you how you can do it. btw i only used groups.

--------------------------------------------------------------- local function createPlayer(nIn,sizeBodyIn,sizeHeadIn,distanceIn) local n=nIn local sizeBody=sizeBodyIn local sizeHead=sizeHeadIn local distance=distanceIn local players=display.newGroup() local posX=0 for i=1, n do local playerGroup=display.newGroup() local body=display.newCircle(playerGroup,posX,0,sizeBody) -- pos 1 is body local head=display.newCircle(playerGroup,posX,body.y-body.contentHeight\*.5-sizeHead,sizeHead) -- pos 2 is head posX=posX+body.contentWidth+distance players:insert(playerGroup) end return players end ------------------------------------------------- local dummy=createPlayer(5,10,5,0) dummy.x=100 dummy.y=100 local dummy2=createPlayer(5,20,10,5) dummy2.x=100 dummy2.y=200 dummy[2][1]:setFillColor(0,1,0) -- player n.2 body is green dummy[2][2]:setFillColor(1,0,0) -- player n.2 head is red dummy2[3][2]:setFillColor(1,0,0) -- player n.3 head is red

test it, change it as you like ofc :slight_smile:

regards.

thanks both :wink:

It was a question for espace3d who start a question on my previous post.

good day.

Does player[2].body:setFillColor(1,0,0) work?

thomas6 solution is correct for your problem.

another approach to creating body/head is doing a function to create the body and head with parameters. that way is easier to create more players.

i’ve made a small code to show you how you can do it. btw i only used groups.

--------------------------------------------------------------- local function createPlayer(nIn,sizeBodyIn,sizeHeadIn,distanceIn) local n=nIn local sizeBody=sizeBodyIn local sizeHead=sizeHeadIn local distance=distanceIn local players=display.newGroup() local posX=0 for i=1, n do local playerGroup=display.newGroup() local body=display.newCircle(playerGroup,posX,0,sizeBody) -- pos 1 is body local head=display.newCircle(playerGroup,posX,body.y-body.contentHeight\*.5-sizeHead,sizeHead) -- pos 2 is head posX=posX+body.contentWidth+distance players:insert(playerGroup) end return players end ------------------------------------------------- local dummy=createPlayer(5,10,5,0) dummy.x=100 dummy.y=100 local dummy2=createPlayer(5,20,10,5) dummy2.x=100 dummy2.y=200 dummy[2][1]:setFillColor(0,1,0) -- player n.2 body is green dummy[2][2]:setFillColor(1,0,0) -- player n.2 head is red dummy2[3][2]:setFillColor(1,0,0) -- player n.3 head is red

test it, change it as you like ofc :slight_smile:

regards.

thanks both :wink:

It was a question for espace3d who start a question on my previous post.

good day.