I've read the help files on both, but I'm missing something.
Where would I use Spawn() over Sleep()? Or Sleep() over Spawn()? Could someone give me an example?
ID:152352
Feb 28 2007, 7:35 am
|
|
Feb 28 2007, 7:43 am (Edited on Feb 28 2007, 8:45 am)
|
|
I usually use spawn when I want to do something recursive or create a bunch of atoms instantly. I use sleep when I just want a delay.
|
In response to Xx Dark Wizard xX
|
|
You can actually do the fill without recursion if you use a list. It's a much cleaner technique.
You've also got some errors in your code, most notably using return if T is null instead of continue. proc Lummox JR |
In response to Lummox JR
|
|
I fixed the error, thats a much better way to do it. Also you should use sleep when you want to wait a certain amount of time.
admin Also note spawn requires a reboot while sleep doesen't. |
sleep() halts the current proc for the specified amount of ticks, then continues it.
spawn() continues the current proc's code then starts a new running thread (like a new running proc, but that is still linked to the current proc) after the specified amount of ticks with the indented statement. You should use sleep() when you want to delay things or wait for some time. spawn() is used for allowing procs such as those with infinite loops to return, so the caller may continue, etc. |
In response to Xx Dark Wizard xX
|
|
Xx Dark Wizard xX wrote:
I fixed the error, thats a much better way to do it. Also you should use sleep when you want to wait a certain amount of time. > admin Also note spawn requires a reboot while sleep doesen't. That doesn't make any sense. spawn() has nothing to do with rebooting, except to the extent that you might use it in a reboot verb or proc. Using spawn() here, as long as you indent the next line as you should, would be identical to using sleep() in this case. Lummox JR |
In response to Lummox JR
|
|
Also, with
admin if the user logs out before the reboot, there won't be a reboot, but if you use a spawn like: admin Then even if the user logs out, it will go ahead and reboot |
In response to Tails5
|
|
Wrong.
There, in BOTH cases, the reboot would occur regardless of the player logging out or not. In the case of mob/verb's, where usr == src, in both cases the reboot would not occur if the player has logged out. This is because: 1) Procs only auto-terminate if their src is deleted - not when usr is. There is therefore no protection for 'usr' being deleted except in mob/verb's. 2) Sleeping procs and spawn()'d threads are also terminated when their src is deleted. |
In response to Kaioken
|
|
Given that it's likely that that was supposed to be a subtype of mob, or that those verbs were going to be added to a mob, src will likely be the same as usr. Which means they will die when someone logs out. But both of them will die, so you were right there. You could do this, though:
verb/reboot(n as num) But there's no real reason to use spawn over sleep. I just prefer it when procedures return. EDIT: Just to make the above comment clearer, there's no real reason to use spawn over sleep in this case. There are other cases where it's a good idea to use spawn over sleep. |