ID:266037
 
I was trying to access one movement style from Move() and ended up with a recursion error. [due to the step function in that movement].

    Move(newLoc, moveDir)
switch(state)
if(STRUGGLE)
if(dir == src.dir && src.struggle)
src.struggle.push(src)
..()


Now if I were to try "spawn() src.struggle.push(src)". I would get "runtime error: Cannot execute null.push()."

Below is part of a sword struggle datum. In struggle mode player movement changes to push/pull movement. It used to work when I had a macro called "tapdir(dir as num)". But i removed this macro due to a recent movement system change.

Struggle
var
mob/player
one = null
two = null

proc
Break(var/mob/player/winner,var/mob/player/loser,var/distance) //had to use Break() since break is reserved
step(winner, turn(winner.dir,180) )
winner.endStruggle()
loser.endStruggle()
loser.knock_back(winner,0+distance,5)


push(var/mob/player/m)
if(m == one)
var/turf/t = get_step(get_step(m, m.dir), m.dir)
if(t)
if(!t.density)
for(var/mob/player/o in t)
Break(m, two)
o.knock_back(m, 1, 5)
return

for(var/obj/dense_object/d in t)
Break(m,two)
return
//Object should take damage!

flick("push_struggle",one)
flick("pushed_struggle",two)
step(two, m.dir)
step(m, m.dir)
else
Break(m,two)

else
world << output("BREAK","output2")
Break(m,two)

else
var/turf/t = get_step(get_step(m,m.dir),m.dir)
if(t)
if(!t.density)
for(var/mob/player/o in t)
Break(m, one)
o.knock_back(m, 1, 5)
return
for(var/obj/dense_object/d in t)
Break(m, one)
return
//Object should take damage!

flick("pushed_struggle",one)
flick("push_struggle",two)
step(one, m.dir)
step(m, m.dir)
else
Break(m, one)
else
Break(m, one)
<Incorrect info. removed so as not to inject fallacies.>

I don't see how using spawn will remove a problem with infinite recursion. That's usually an issue with logic, which spawning wouldn't prevent.

Anyways, I don't see why this is in Design Philosophy and not somewhere else, like Code Problems.

And it would help if you explained what you were trying to accomplish. Like, instead of posting code, just explain what the push proc does.
I don't think people want to examine your code to figure out what it does. It's much faster if you just tell us.
I don't even know what you mean by "sword struggle." And what is moving (Move proc) even supposed to mean in that case?
In response to Complex Robot
Of course 'src' is defined in spawned sections of code, anything that worked before the spawn() will work after it if the references still exist. The runtime error he was getting was caused by one of the variables belonging to src was null. So calling a proc for that reference variable would spit out a runtime error.
In response to Nadrew
Nadrew wrote:
Of course 'src' is defined in spawned sections of code, anything that worked before the spawn() will work after it if the references still exist. The runtime error he was getting was caused by one of the variables belonging to src was null. So calling a proc for that reference variable would spit out a runtime error.

Showing how dumb I am about spawn, again.
Thank you for correcting me.
I guess I'll re-read his post to see if I can get what he's saying.