The problem with the generation of land under the player

I have a function called CreateGround, it creates a surface under the player and if it already exists on the site of the land, it moves along the x-axis to x + the width of the surface, but for some reason it refuses to work, I hope that you will help me.

Here’s the code:

local function createGround () &nbsp; local ground = display.newImageRect( mainGroup, objectSheet, 3, 390, 265 ) &nbsp; ground.x = 195 &nbsp; ground.y = yc+(yc\*0.9) &nbsp; table.insert( groundTable, ground ) &nbsp; for i = #groundTable, 1, -1 do &nbsp;&nbsp;&nbsp; local thisGround = groundTable[i] &nbsp;&nbsp;&nbsp; if (thisGround.x == (thisGround-1).x) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (thisGround-1).x = (thisGround-1).x + 390 &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; if (thisGround.x \< 500 or thisGround.x \> width+500) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; display.remove( thisGround ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; table.remove( groundTable, i ) &nbsp;&nbsp;&nbsp; end &nbsp; end end

Error screen attached

It’s this line that’s causing the error:
 

 if (thisGround.x == (thisGround-1).x) then

You’re trying to minus one from “thisGround” which is, presumably, a display object?

Did you want something more like this:

 if ( thisGround.x == ( groundTable[i - 1] ).x ) then

If that’s the case you’ll also still want some safety checks in there to make sure there is an element in the groundTable at that index before you start accessing properties on it.

It’s this line that’s causing the error:
 

 if (thisGround.x == (thisGround-1).x) then

You’re trying to minus one from “thisGround” which is, presumably, a display object?

Did you want something more like this:

 if ( thisGround.x == ( groundTable[i - 1] ).x ) then

If that’s the case you’ll also still want some safety checks in there to make sure there is an element in the groundTable at that index before you start accessing properties on it.