Script File: Difference between revisions
m (→See also) |
m (→Execution) |
||
Line 25: | Line 25: | ||
* Scripting lines in the [[Mission Editor]] | * Scripting lines in the [[Mission Editor]] | ||
* [[Event Handlers]] in addon config files | * [[Event Handlers]] in addon config files | ||
The commands to execute scripts are: | The commands to execute scripts are: | ||
Line 39: | Line 40: | ||
; call (Armed Assault only) | ; call (Armed Assault only) | ||
: [[call]] executes a [[compile|compiled]] script or code within the scope of the current script. Such code is considered a [[Function|function]]. The following statements do not apply for functions. | : [[call]] executes a [[compile|compiled]] script or code within the scope of the current script. Such code is considered a [[Function|function]]. The following statements do not apply for functions. | ||
Scripts are running ''besides'' the executing instance in own threads. That means that the executing instance (f.i. script or [[Function|function]]) doesn't wait for the script to end. Thus scripts should not be used for code that should return a value, which is used in the calling script. This part is taken over by [[Function|functions]]. | Scripts are running ''besides'' the executing instance in own threads. That means that the executing instance (f.i. script or [[Function|function]]) doesn't wait for the script to end. Thus scripts should not be used for code that should return a value, which is used in the calling script. This part is taken over by [[Function|functions]]. |
Revision as of 02:00, 22 December 2006
A script is a chunk of code grouped together in a seperate textfile. This code does a specific task handled by the game engine. The common extensions for scripts are .sqs and .sqf, depending on the used syntax (see below). You can use any text editor like Notepad to edit scripts.
A special kind of a script is a function.
Usage
Scripts are mainly used for any game processes where timing is important. They are different to functions where the result or calculation is important.
Thus scripts can be used for cutscenes, dialogs, radio scripting and much more.
Syntax
In Operation Flashpoint, scripts are limited to SQS syntax.
In Armed Assault, the already existing SQF syntax was introduced for scripts. SQS syntax is still usable, but is considered deprecated in Armed Assault.
Execution
Scripts can be executed from several points in the game:
- Other scripts
- Other functions
- Scripting lines in the Mission Editor
- Event Handlers in addon config files
The commands to execute scripts are:
- exec
- exec starts thread for scripts in SQS syntax.
- execVM (Armed Assault only)
- execVM starts thread for scripts in SQF syntax.
- spawn (Armed Assault only)
- spawn starts a thread for a compiled script or code and returns a script handle.
- call (Armed Assault only)
- call executes a compiled script or code within the scope of the current script. Such code is considered a function. The following statements do not apply for functions.
Scripts are running besides the executing instance in own threads. That means that the executing instance (f.i. script or function) doesn't wait for the script to end. Thus scripts should not be used for code that should return a value, which is used in the calling script. This part is taken over by functions.
Since Armed Assault, scripts return a script handle which you can use to verify whether a script is still running.
nserted from sqf syntax
With the release of Armed Assault, the SQS syntax for scripting was deprecated. SQF syntax is expected to be used for both scripts and functions.
SQS syntax is compiled line-by-line as it is executed. SQF files must be compiled ahead of time and are thus more efficient at time of execution. SQF scripts are compiled and executed with either the execVM command or manually via compile and spawn. Since scripts run parallel with each other, you must use scriptDone if you wish to have a calling script wait for a called script to finish.
Diagram of Scripts Running in Parallel
Diagram of Scripts Running in Parallel using waitUntil and scriptDone to pause execution
Special Variables
_time in both syntax ?
Special Commands
Due to the fact, that calling instances aren't waiting for the scripts to end, scripts can be halted for a custom period of time. There are different methods to do this in SQF syntax (Armed Assault only) and SQS syntax (deprecated since Armed Assault).
SQF syntax
- Delay
- You can set the script to sleep for a number of seconds using the command sleep.
STATEMENT 1; // wait 10 seconds sleep 10; STATEMENT 2;
- Waiting for a condition
- You can set the script to sleep until a specific condition is met using the command waitUntil.
BOOL = false; // wait until BOOL gets true waitUntil BOOL; STATEMENT;
SQS syntax
- Delay
- You can set the script to sleep for a number of seconds by introducing a line with ~, followed by the number of seconds.
STATEMENT 1 ; wait 10 seconds ~10 STATEMENT 2
- Waiting for a condition
- You can set the script to sleep until a condition is met by introducing a line with @, followed by the condition.
BOOL = false ; wait until BOOL gets true @BOOL STATEMENT
- Waiting for a time
- You can set the script to sleep until a time (number of seconds since the beginning of the script) is met by introducing a line with &, followed by the time.
&100 ; is equivalent to @_time >= 100