ID:273089
 
I'm not sure, I think this may be a bug, but I'm not so sure about it that I'm going to put it there. I'm assuming that it's just behavior I don't know about.

proc/SomeProc()
var/someVar=0
spawn()
while(true)
sleep(5)
world << someVar
someVar=1
while(true)
sleep(5)
world << someVar

This code will produce output alternating between 0 and 1. The only thing that I can imagine is that spawn() actually creates two different someVar variables, which is somewhat frustrating. I was trying to use a variable to ensure that both halves of the spawned code had finished before I did something else, but I couldn't figure out why, until I noticed this.

Here's one possible solution although others may chime in with some additional design advice.

var/global/someVar = 0;


More info can be found here:
http://www.byond.com/docs/guide/
Section: The Life of a Variable

ts


Yes, it's supposed to be this way. 'Spawned' code isn't even really a part of the proc, and typically when it executes, often the proc that queued it had even already terminated; therefore it couldn't use a proc's actual local vars. The vars are indeed just copied in the new mini-procedure that runs.