ID:270128
 
I am just wondering about spawn(). Ill use this code as an example:

mob
proc
RunSpawn()
var/sr=src
spawn(50)
world<<"[sr]"
del(src)

Now this is just a simple example, but I cant get it to work. Because it deletes it sr will just become null. Another example would be a potion where you drink it and its effect lasts for a certain amount of time, but it deletes the potion as soon as you drink it. Now the answer is probaly easy but how do I get this to work?

ADT_CLONE
Spawn will count the ticks you give it, then do everything inside of it. In this case, it will delete you first, then after spawn() is done, will do whatever is inside of it. Unlike sleep, spawn dosen't completly stop the proc/verb you use it in.
src.loc=null
This removes it from the contents but does not delete it.

The garbage collector MIGHT pick it up this way, so try adding it to a list untill your finished with it.
In response to Cheetoz
But it never does. Basically, I get a proc which as an argument which is a player.

Then I set a varible on the player to 1, spawn for a certain amount of time, delete the potion, and then when the time is up set that varible to 0.

In response to ADT_CLONE
Didn't see that little chunk under the code, I was thinking of something else. But, the way Flame Sage described is the only thing I can think of in this case.
Whenever you delete an object, all procs that are running will stop, and all references to them will become null. If you really want to delete the potion right after you use it, carry on the effect through another proc.

obj/potion
proc/Use(mob/M)
M << "You have used the potion!"
M.CarryPotionEffect()
del(src)

mob/proc
CarryPotionEffect()
spawn(100)
src << "The potion's effect has run out!"


If you still need information from the potion, you shouldn't delete it, but send it to a null location (and keep its reference stored), then delete it when it is done in use.

~~> Unknown Person
In response to Unknown Person
One thing to note is you can do src = null and delete the obj and the proc/verb will continue to run even after the obj has been deleted.
In response to tenkuu
Ok, and UP, that doesnt work.