ID:165905
 
proc/loopingproc()
spawn(600)
world << "AGAIN AGAIN AGAIN!"


If you loop something with the spawn() thingy like that, it won't made the world go kersplodes every 100 or so loops, right?

I need to loop for what I wanna do but the people on my games don't like kersplodes; but the thing I wanna do won't benefit them at all so if it'll significantly reduce the lifespan of Dream Daemon I probably shouldn't do it :(
Why not use a while()?
In response to Mechanios
because my mind doesn't work that way :(

and I dunno
In response to Cowdude
Well, what're you trying to loop? haha
In response to Mechanios
I'm just making an NPC say something to the view over and over to bug people or something
In response to Cowdude
yea so under New() for the NPC just call src.blah()

mob/NPC/proc/blah()
while(src)
sleep(600)
//using spawn would make the loop go over and over cause spawn contionues the code,
//but still waiting 600 ticks. sleep stops the code and waits for 600 ticks.
world << "Har Har HAR!"
In response to Mechanios
except I said view so it'd be "view(src)" instead of "world" but k
In response to Cowdude
Haha. My bad.
Yep, that'll make it not kersplode.

The reason it kersplodes is because something called the 'stack' gets too big. The stack for a procedure records where it's been called from so it can return data to the right place, basically. Spawn() means that it's starting a new stack, rather then continually adding to the same one. If you kept adding to the same one, ala this:

proc/Kersplode()
sleep(600)
Kersplode()


the stack for the Kersplode() proc will eventually overrun the limit that has been set for it, and it will die a horrible, painful, stack-overflow death.
In response to Jp
You should try to use <code>while()</code> whenever you can.
For example, the <code>Kersplode()</code> proc can be rewritten like this:

proc/Kersplode()
while(world)
sleep(600)
...
In response to Android Data
Are you sure the While proc won't stack up and kill the game? :( it just crashed twice in the last 6 hours or so :( maybe I'll just take out those NPCs and see how long it lasts. The game usually lasts a good 100-300 (yeah it varies that much) hours; until today it was up at least 112 (then it crashed and I updated and added the NPCs this thread was originally about)


The NPCs are awesome, though! :D
In response to Cowdude
Using <code>sleep()</code> would stack the procs up and crash the proc eventually. Using <code>while()</code> is harmless, unless you remove the <code>sleep()</code> within it, or it'll crash the server.