ID:2432715
 
(See the best response by Spevacus.)
Code:
// B is the target...
var/obj/N = new(B.loc)//Place Holder, saving location of where skill landed.
while(I<3)
I++

spawn()new/mob/Traps/Poison (N.loc)
N.x+=1


Problem description: All traps end up at ending B.loc . I believe this is due to loc being a reference.

I've boiled down some more complicated code (in a New(var,var,var,var)). I believe my problem is that BYOND is passing variables by reference, which in turn is moving my traps as the target/object moves.

I'm sure I'm doing something stupid, but is there some way to dynamically pass a location without it being by reference?

Thanks,
Iron
Hmmm...

Have you considered using...
var/obj/N = new
N.loc = B.loc


I believe having B.loc inside of a new() call is refreshing it by reference. Would you mind trying that for me?
In response to Spevacus
Your code actually ties N to B's location.
Where as before N kept it's own location, which I want.

Imagine N as a paintbrush. I'm trying to paint traps across the terrain. However all the traps end up on N's final location.

EDIT: And the paintbrush is optional, I'd actually prefer to just pass calculated locations to the new object (thus avoiding a painter object all together). Yet I still need to original coords in order to do so. And point a variable at them gives me a reference to the target's coords.
Spevacus, I don't think you understand the problem.

Increment the x coord by 1 or by I results in the same issue. The traps are still tied to the location of N by reference.

I need to traps to self contain their own coords.
T1=X, T2=X+1, T3=X+2
Best response
I think the spawn() is messing with you here in your while loop. It might be permitting all of the while loop to go through to its end before creating the trap.

Deleted my last response, it was way off track.
In response to Spevacus
You're on track with the spawn.
Appreciate the help!

So for those reading in the future... spawn() was allowing the loop to fully iterate. As a result setting all my traps at the same location.
Awesome, glad that worked out for you. Sorry for the initial confusion, I shoulda re-read your question a couple more times.
You can use spawn(-1) to execute the spawned code before the rest. With a spawn delay of 0, the spawned code happens "after" the rest of the code this tick (but still in the same tick). With -1 as the delay, the inner code happens first until it reaches the end or another delay, then the outer code happens.

Alternatively, add "set waitfor = 0" to the top of your New() override. I'm assuming your New contains a delay, otherwise you wouldn't be spawning it in the first place.
Yep. The trap has a loop. Thought I could probably rewrite it to be event driven. (working on an old project).

"set waitfor=0" is key.

Thanks again!