ID:178342
 
No, I'm not asking what an infinite loop is. I'm asking WHY I get an infinite loop with this code (for an object). This is what I have...
    Rocks
icon = 'Rocks.dmi'
var/Right
var/Left
New()
for(var/obj/Rocks/R in (src.x+1),src.y,src.z) src.Right = 1
for(var/obj/Rocks/R in (src.x-1),src.y,src.z) src.Left = 1
if(Right==1 && Left==1) icon_state = "Center"
else if(Right==1) icon_state = "Left"
else if(Left==1) icon_state = "Right"
Any idea what's wrong? I get infinite loops for every "Rocks" on the map, no matter what. How can I fix this?
Your primary trouble is that New() does not call the default New(). Add this line:

..()

to the beginning of your New() proc.

I'm surprised it is even compiling with the arguments in those for() loops. If you want to search for all the Rocks in the turf to the right of src, you would want to use locate() of get_step() to find the space to the right.

for(var/obj/Rocks/R in get_step(src,EAST))
src.Right = 1
break // this stops the loop after it finds the first rock

If you happen to have a BYONDscape subscription, you may want to look over my AtomMerge library. It demonstrates a method to check all the surrounding turfs for matching items in the atom's New() proc.