goto
Function
Makes the thread execution jump to a label line which can be located anywhere in the script. The goto command can also point to the name of the thread in which it's located since a thread name is followed by a colon and counts as a label too. It can point to the name of another thread as well. Useful for controlling the order of execution of commands within a thread, jumping to another thread and making threads loop continuously.
Syntax
|
goto <label_name>|<thread_name>
|
Notes & examples
|
Label lines, like the first line of a thread definition, must always be followed by a colon (:).
Example of use of the goto command:
example1_thread:
goto camera2_shot
camera1_shot:
cuecamera $camera1
wait 6.8
goto end_of_thread
camera2_shot:
cuecamera $camera2
wait 15.2
goto camera1_shot
end_of_thread:
end
In the previous example, the goto commands are used for the sole purpose of inverting the order of execution of the camera1 and camera2 shots.
Note:
In practice, the above thread is unnecessarily convoluted and not a very efficient way to do things. I just wrote it that way to illustrate what the command does.
Example of the typical use of a goto command after a variable conditional test:
example1_thread:
local.playcount = 1
play_it_again_sam:
cuecamera $camera1
wait 6.8
cuecamera $camera2
wait 6.8
local.playcount += 1
local.playcount ifnotequal 3 goto play_it_again_sam
end
In this example, the thread will make the game the view cue to camera1, remain 6.8 seconds in that view, then cue to camera2 and remain there for 6.8 seconds. Since the first time around, the value of local.playcount will be 2 (therefore not equal to 3), the conditional test will return "true" and the "goto play_it_again_sam" will be executed. This will make the camera cueing command be executed a second time. Afterwards, the value of the variable local.playcount will be incremented to 3 which will make the conditional test return "false" and the goto command will not be executed. The thread will then be able to move on to the next command which ends its execution.
Important distinction: although the goto command can be used to jump to the beginning of another thread, a goto <thread_name> is not the same thing as a thread <thread_name> command. Here are 2 examples using the same threads:
Jumping to another thread using the goto command:
camera1_thread:
cuecamera $camera1
wait 6.8
goto camera2_thread
$camera1 playsound "weapons/camgun/newmix.wav"
end
camera2_thread:
cuecamera $camera2
end
In this example, the thread will execute the "cuecamera" and "wait" commands. Then the following "goto" command will jump straight to "camera2_thread:" and the "$camera1 playsound" command in the first thread will not be executed (the sound won't be played). The second thread will terminate but the first one will remain open indefinitely.
Calling another thread using the thread command:
camera1_thread:
cuecamera $camera1
wait 6.8
thread camera2_thread
$camera1 playsound "weapons/camgun/newmix.wav"
end
camera2_thread:
camera2:
cuecamera $camera2
end
Now in this example, the thread will execute the "cuecamera" and "wait" commands just like in the previous example. BUT, unlike in the previous example, the following "thread" command will call the thread "camera2_thread:" and then execute the "$camera1 playsound" command. At the same time than the sound is played, the command in "camera2_thread" will also be executed. In this case, both threads will be able to terminate.
The main difference is that a "goto" just causes the execution of the commands to jump to a specific place in the script. A "thread" command starts a new thread of execution which runs independently of the thread from which it was called.
|
|