Change values in a table and refresh object position

Objeto1=display.newRect (300,0,50,50)

Objeto1:setFillColor (1,0,0)

Objeto2=display.newRect (300,100,50,50)

Objeto2:setFillColor (0,1,0)

Objeto3=display.newRect (300,200,50,50)

Objeto3:setFillColor (1,0,1)

Objeto4=display.newRect (300,300,50,50)

Objeto4:setFillColor (0,1,1)

Objeto5=display.newRect (300,400,50,50)

Objeto5:setFillColor (1,0,0)

Objetos={Objeto1.x,Objeto2.x,Objeto3.x,Objeto4.x,Objeto5.x}

Objetos2={Objeto1.y,Objeto2.y,Objeto3.y,Objeto4.y,Objeto5.y}

How do I update some value in the table when an object changes its position?

And the other question would be: How do I refresh the position of the object when I change a value in the table?

Store (a reference to) the objects in your arrays and then reference them like this - Objetos[1].x Objetos[1].y.

You can put all the references in a big table :

local tab={} local color={ {1,0,0},{0,1,0},{1,0,1},{0,1,1} } for k=1,4 do local o=display.newRect(300,(k-1)\*100,50,50) o:setFillColor(unpack(color[k])) table.insert(tab,o) end local o5=display.newRect(300,400,50,50) o5:setFillColor(unpack(color[1])) table.insert(tab,o5) /// and now you work with the table "tab" only local Objetos,Objetos2={},{} local function check(event) for k=1,5 do local o=tab[k] Objetos[k]==o.x Objetos2[k]==o.y end end Runtime:addEventListener("enterFrame",check)

There is no need to code anything!

As per my last answer…  as your array now stores pointers to your objects if your objects move then when you reference the array you will automatically read the updated values.  If you set values in the array this will automatically update your objects.

i.e. 

Objetos[1].x Objetos[1].y will directly read the x and y values of Objeto1

if you set Objetos[1].x = 50 then Objeto1.x will be 50.

Store (a reference to) the objects in your arrays and then reference them like this - Objetos[1].x Objetos[1].y.

You can put all the references in a big table :

local tab={} local color={ {1,0,0},{0,1,0},{1,0,1},{0,1,1} } for k=1,4 do local o=display.newRect(300,(k-1)\*100,50,50) o:setFillColor(unpack(color[k])) table.insert(tab,o) end local o5=display.newRect(300,400,50,50) o5:setFillColor(unpack(color[1])) table.insert(tab,o5) /// and now you work with the table "tab" only local Objetos,Objetos2={},{} local function check(event) for k=1,5 do local o=tab[k] Objetos[k]==o.x Objetos2[k]==o.y end end Runtime:addEventListener("enterFrame",check)

There is no need to code anything!

As per my last answer…  as your array now stores pointers to your objects if your objects move then when you reference the array you will automatically read the updated values.  If you set values in the array this will automatically update your objects.

i.e. 

Objetos[1].x Objetos[1].y will directly read the x and y values of Objeto1

if you set Objetos[1].x = 50 then Objeto1.x will be 50.