ID:155682
 
obj
proc
Interact()

door
icon = 'Core.dmi'
icon_state = "door"
density = TRUE

Interact(mob/M)
var
turf/T = loc

loc = null

sleep(30)

while(!Move(T))
sleep(10)

client
verb
Door()
new /obj/door(usr.loc)

Interact()
for(var/obj/O in get_step(usr, usr.dir))
O.Interact(usr)

Center()
Interact()


Is the above code capable of crashing my world? When a player opens a door it's moved to null and then unless something is blocking the tile the door was on, it's moved back. Is it possible this could crash my game though if someone went AFK on the door spot and lever let it return?
No, as it is it's solid, because they can only call Interact when the door object is in place.

However, for loops like this, I'll sometimes create an "ID" object variable to prevent starting more than one of them. Basically, you increment the variable each time you start the loop, and store its value in a local variable of the process. Then inside the loop conditional, you check that the object's loop ID hasn't changed from the stored local value (if it has, that indicates another loop has started, and this one should end).

Another option would of course be storing a boolean value as to whether or not a loop is running, but if the loop crashes and leaves the boolean as true, the code will stop working. So you have to make very robust code.

But again, the circumstances of how this loop is initiated and ended more or less guarantee only one can be running.

My only worry would be if there's any chance of that turf being replaced (such as in a building game), you should also check that T is true in the loop conditional (and if not, also delete the door object)