[Resolved] Getting an exception when trying to tile ground

I’m using the following code:

ground1.x = ground1.x - 10  
 ground2.x = ground2.x - 10  
 ground3.x = ground3.x - 10  
 ground4.x = ground4.x - 10  
 ground5.x = ground5.x - 10  
 ground6.x = ground6.x - 10  
 ground7.x = ground7.x - 10  
 ground8.x = ground8.x - 10  
  
  
 if(ground1.x \< ( 0 - 75 ) ) then  
 ground1:removeSelf()   
 ground1 = ground2  
 ground2 = ground3  
 ground3 = ground4  
 ground4 = ground5  
 ground6 = ground7  
 ground7 = ground8  
 local num = math.random ( 1, 4 )  
 ground8 = display.newImage( group, "normalground"..num..".png", ground7.x + ground7.contentWidth/2, display.contentHeight - 52 )  

to animate a moving ground. I’m using 8 tiles, ground1-ground8. This code is inside my animate function that is called on “enterFrame”.

What I’m trying to do is detect when “ground1” has moved off the left edge. Then, I’m reassigning the tile ground2 to ground1, ground 3 to ground2, etc, and at the end, creating a new tile and assigning it to ground8.

I did something similar with my background scrolling, which is working fine. However, when I try to run this code, it works for a while (it scrolls the first 4 tiles successfully) but once it tries to assign tile 5 to ground1 and go back through the animation process, I get the following exception:

attempt to perform arithmetic on field ‘x’ (a nil value)

Any ideas? [import]uid: 147975 topic_id: 27181 reply_id: 327181[/import]

Between lines 16 and 17 you go straight from ground4 to ground6 - I suspect that may have something to do with it. [import]uid: 52491 topic_id: 27181 reply_id: 110463[/import]

Great! Thanks. That worked. I figured I just needed another set of eyes to look it over… [import]uid: 147975 topic_id: 27181 reply_id: 110471[/import]

No worries Chase :slight_smile: [import]uid: 52491 topic_id: 27181 reply_id: 110609[/import]