Loop an existing object

how can I loop this? so that i can change all locals setfillcolor to 1

this is my code and it does’nt work, just want to show my logic.

local x1 = display.newRexct(0,0,150,50)

x1:setFillColor(0.2)

local x2 = display.newRexct(0,0,150,50)

x2:setFillColor(0.3)

local x3 = display.newRexct(0,0,150,50)

x3:setFillColor(0.4)

local x4 = display.newRexct(0,0,150,50)

x4:setFillColor(0.5)

local xx

for i = 1,4 do

   xx = “x”…(i) 

   print (xx) – shows x1,x2,x3,x4

   xx:setFillColor(1) – error here

end

thanks in advance

[lua]

local rects = {}

local cols = {0.2, 0.3, 0.4, 0.5}

for a = 1, #cols, 1 do

  local r = display.newRect(0,0,150,50)

  r:setFillColor(cols[a])

  r.id = a

  rects[#rects+1] = r

end

for a = 1, #rects, 1 do

  rects[a]:setFillColor(1)

end

[/lua]

hmmm how can I set the object.id as “1” “2” “3” and so on?

Edited the code to include this.

i see thanks a lot nick_sherman

:slight_smile:

[lua]

local rects = {}

local cols = {0.2, 0.3, 0.4, 0.5}

for a = 1, #cols, 1 do

  local r = display.newRect(0,0,150,50)

  r:setFillColor(cols[a])

  r.id = a

  rects[#rects+1] = r

end

for a = 1, #rects, 1 do

  rects[a]:setFillColor(1)

end

[/lua]

hmmm how can I set the object.id as “1” “2” “3” and so on?

Edited the code to include this.

i see thanks a lot nick_sherman

:slight_smile: