ID:140559
 
Code:
Click()
if(usr.turn==1)
if(usr.moving==1)
usr.dir=get_dir(usr,src)
sleep(1)
step(usr,usr.dir)
usr.moving=0
usr.turn=0
for(var/obj/O in world)
if(O.owner==usr)
del(O)


Problem description: This code comes from a tile where if you click it, the user moves onto it. There are 4 that are created when you click a button and I need them to disappear after clicking one of the tiles.

They should disappear, but only the one I clicked disappears.

I take it that you are attempting to delete the atom that is running the proc as well (even through you claim that it is a 'tile', which would be turf and are looping through obj), in which case it is likely that this atom is found before the others.
Did you consider what would happen to an atom's proc when the atom is deleted (Hint: It's terminated instantly)?

As a side-note, you might want to reconsider the way you're getting the reference to the atoms you want deleted.
Looping through each obj in the world seems a waste for that kind of task, when you could simply store the reference in a list upon creation.
In response to Schnitzelnagler
Schnitzelnagler wrote:
Looping through each obj in the world seems a waste for that kind of task, when you could simply store the reference in a list upon creation.

Indeed, using a list fixed it completely.

In response to Mickemoose
It only camouflages the problem, unless you reconsider the design and apply separation of concern (as in deleting the atoms in a proc that is not inherited by the atom itself).
In response to Schnitzelnagler
The problem can be resolved (slightly messily) by changing del(O) to:

if(O == src)
spawn() del(O)
else
del(O)


It's a fair bit easier than redesigning everything and it's unlikely that there would be any bad consequences.

Or, if you want to make things even messier, just put

src = null


in there, which will allow it to continue running even when you delete src... but that's ESPECIALLY messy, though I suppose it's marginally less likely to cause errors.
In response to Garthor
...Or you can just use the common, simple solution of skipping deleting src in the loop, then deleting it last (if needed), at the end of the proc.
In response to Kaioken
If proposing esoteric solutions to simple problems is wrong, then I don't want to be right.
In response to Garthor
And how does that have to do with the situation? o_O
Okay, I get it, you're right. Proposing esoteric solutions is better than proposing the good solutions. Yay for you..?