Page 1 of 2
Waiting for a thread to end?
Posted: Sat May 03, 2003 2:04 pm
by Bjarne BZR
I wonder:
If I have this method:
( Just a stooopid example method )
...and I want the calling script to be able to halt until the method has ended. I cant do this:
...because that would create a separately executing thread and the calling script will continue on its next line.
I want something like:
...or just...
I'm pretty shure I saw the syntax for this somewhere, but I can't seem to remeber / find it again....
I'm writing
a tutorial on scripting, so I want to get it right.... ( Feedback is welcome )
Posted: Sat May 03, 2003 2:24 pm
by jv_map
waitthread a_method
8)
Posted: Sat May 03, 2003 2:33 pm
by Bjarne BZR
Yep, thats the one
And while I have your atension jv:
Passing parameters at thread creation, wats the syntax for that? ( I'm not talking about setting the self object )
And how do you access the parameters in the thread?
Posted: Sat May 03, 2003 2:40 pm
by mohaa_rox
and exec and wait is
waitexec right?
Posted: Sat May 03, 2003 2:43 pm
by Bjarne BZR
This exec command... is that like:
exec <scriptfile>::label
is equal to
waitthread label
?
I havent really figured the exec command out...
Posted: Sat May 03, 2003 2:46 pm
by jv_map
waitexec is a little different as it waits for the entire thread group to finish.
To pass an argument:
Code: Select all
waitthread mythread 1 2 3
mythread local.one local.two local.three:
println "I can count to three: " local.one " " local.two " " local.three
end

Posted: Sat May 03, 2003 2:48 pm
by mohaa_rox
Maybe not, that's a thread and that's to execute. Things like "exploders", bombers, etc use "exec" at the top before level waittill spawn. And I think waitthreads are mainly used for xxx.scr::xx like objectives, and "exec" are maybe like "exec global/missioncomplete.scr".
In SP, it's like this:
levelend:
waitthread global/objectives.scr::current_objectives 0
wait 1
exec global/missioncomplete.scr
end
Posted: Sat May 03, 2003 2:50 pm
by jv_map
The only difference I know is that with exec you only have to supply a script file, thread actually requires a label.
Example:
exec global/exploder.scr
thread global/exploder.scr::main // (or something)
Posted: Sat May 03, 2003 2:52 pm
by mohaa_rox
Yeah, and
exec global/weather.scr
waitthread global/weather.scr::main
I think exec the .scr is the WHOLE thing, while thread the main may only be that part, provided if they don't link the threads.
I dunno.
Posted: Sat May 03, 2003 3:02 pm
by Bjarne BZR
So... if I use waitexec XXX, it will not return control to the caller until all the threads in the group has terminated ( including calls like thread YYY inside the XXX method) ?
But if I use waitthread XXX, it WILL return control to the caller as soon as the waitthread XXX has terminated ( ignoring if a thread like thread YYY that is created inside the XXX method has not terminated yet ) ?
Wild guessing here... set me straight...
( can you write waitexec XXX at all without defining the fully qualified label, including the script file name and path? )
Posted: Sat May 03, 2003 5:24 pm
by jv_map
Yes, all correct, but remember thread groups are a bit weird. In most cases, a new thread is part of a seperate thread group. A thread only belongs to the parent thread group if it's in the same file and self is not defined (equal to self of parent thread).
Example:
Code: Select all
$myobject waitexec <myscript>::mythread
mythread:
thread myotherthreada
self thread myotherthreadb
end
myotherthreada:
wait 5
end
myotherthreadb:
wait 10
end
In this example, myotherthreada belongs to the same thread group as mythread, but myotherthreadb has its own thread group (since it has 'self' in front of the call). Therefore the waitexec line will only wait till myotherthreada is finished.
Pop quiz for Bjarne BZR
Posted: Sun May 04, 2003 8:22 am
by tltrude
Ok here is a pop quiz for Bjarne BZR:
In the above example, how long will $myobject wait?
A. 5 seconds
B. 10 seconds
C. 15 seconds
D. Forever
E. None of the above
Posted: Sun May 04, 2003 10:59 am
by Bjarne BZR
Pop quiz!!!! Wohoooo!
The anwer is E. None of the above...
...because the call
$myobject waitexec <myscript>::mythread will fail. ( You can't name a file <myscript> ).
Thanx a bunch JV!
Posted: Sun May 04, 2003 11:34 am
by mohaa_rox
THis works for an AI:
$stupidAI waitexec global/standstill.scr
OR
$stupidAI waitexec global/disable_ai.scr
Right?
And a driveable tank:
$mytank waitthread global/vehicles_thinkers.scr::players_tank
Mountable jeep:
$myjeep waitthread global/vehicles_thinker.scr::player_jeep_controller
Posted: Sun May 04, 2003 11:46 am
by Bjarne BZR
Oh, and I found a command named 'throw( String label )' with the chrystal clear explanation: "Throws to the specified label.".
As my guess here is that its not an Exception throw, what is it? Anyone?