How do I set values to objects that are part of a list

So, I have a bunch of objects that will have similar properties. Naturally, I put them all in a list. The problem is that once I try to change the properties of those bodies, I get an error saying it expects a “=” sign next to the object. My best guess is that it is due to the object already being a property of the array, so I am trying to change a property of a property, but I don’t yet fully understand how the language works to be sure. What am I doing wrong, and how should I achieve making it work?

Here is a sample of my code that I am talking about

local Stairs = {} Stairs[1] = display.newRect(50, 407, 20, 80 ) Stairs[2] = display.newRect(270, 407, 20, 80 ) Stairs[3] = display.newRect(160, 308, 20, 104 ) i=1 while (i \<= 3) do physics.addBody( Stairs[i], "static", {bounce=0}) Stairs.i.isSensor i = i+1 end

 

physics.addBody( Stairs[i], "static", {bounce=0}) -- This is correct: Stairs[i] Stairs.i.isSensor -- This is incorrect: Stairs.i

Also, with loops like like, you should probably just use for loop instead of while, i.e.

for i = 1, 3 do physics.addBody( Stairs[i], "static", {bounce=0}) Stairs[i].isSensor = true end
physics.addBody( Stairs[i], "static", {bounce=0}) -- This is correct: Stairs[i] Stairs.i.isSensor -- This is incorrect: Stairs.i

Also, with loops like like, you should probably just use for loop instead of while, i.e.

for i = 1, 3 do physics.addBody( Stairs[i], "static", {bounce=0}) Stairs[i].isSensor = true end