ID:165751
![]() Nov 6 2006, 7:43 am
|
|
How do I make a proc that activates a list of other procs at the same time without waiting for each one to stop befor activating the next?
|
![]() Nov 6 2006, 7:44 am
|
|
Look up spawn().
|
You missunderstand. I don't want it to wait.
At the moment i have a list: proc/DoList() Where thing1 could take serval seconds to complete. At the moment it WAITS for thing1 to complete before doing thing2. I don't want that. I want them done at the same time, but how? |
Read what DAU said...
sleep() makes you wait, you can think spawn() as a "wait till a certain time passes and run it like a new instance without pausing the original statement" [unlike sleep()]. If you looked it up, in the information, very first line of the paragraph states: Run Statement after a delay. So you want: proc/DoList() - GhostAnime |
You must always always always put some space between code and a // comment on the same line. A tab's worth is usually good, or in the case of the forums, probably 2-4 spaces.
Lummox JR |
Atomixkid wrote:
You missunderstand. I don't want it to wait. He understood you perfectly; you just didn't fully read through the reference on spawn(). While you can use spawn() to delay when a proc runs, you don't have to have any delay at all. At the moment i have a list: proc/DoList() Where thing1 could take serval seconds to complete. At the moment it WAITS for thing1 to complete before doing thing2. I don't want that. I want them done at the same time, but how? Well, doing them at the same time isn't strictly possible; DM will either do one or the other, since it's not multithreaded. However you can make thing2() work while thing1() is working if the former uses sleep(). Here's a way of doing that: spawn(-1) thing1() spawn(-1) means to start on thing1() right away, but since this was spawned out, if it goes to sleep then control passes back to this proc which will run thing2() next. Bear in mind, if thing2() depends on any of the results from thing1() (like setting up values in a list, etc.), it'll behave unpredictably. If you want thing3() to wait for thing1() and thing2() to both finish, it gets a bit trickier, but this can be done too. var/done In either sleep() or spawn(), waiting is not necessarily the point of using them. sleep() without a number will just simply see if any other procs that were spawned are waiting for their turn. spawn(-1) runs the spawned block immediately, while spawn() will run it right after the current proc is finished (or the first sleep() is encountered). spawn(5) will wait half a second before running the procs in the spawn block, and sleep(5) will wait half a second--in which time other procs can operate--before continuing. Also, if you have a proc that takes a long time to compute something but doesn't call sleep() manually, you can use this:
set background = 1
That setting in the proc means it will sleep on its own, and let other procs run if they need to. However it's best to call sleep() yourself at spots where it makes sense to do so. Lummox JR |