Script File: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Lou Montana moved page Script (File) to Script File: name standard)
(40 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Stub}}
{{TOC|side}}
A [[{{PAGENAME}}|script file]] is multiple commands and arguments defining wanted behaviour from the game, all grouped together in a textfile. This code does a specific task handled by the game engine. The common extensions for Arma scripts are '''.sqf''' and '''.sqs''', depending on the used syntax: [[SQF Syntax|SQF]] or (deprecated) [[SQS Syntax]].
{{Feature | Informative | See [[:Category:Community Tools#Code Edition|Community Tools - Code Edition]] for recommended text editors.}}


A '''script''' is a chunk of code grouped together in a seperate file. 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).


A special kind of a script is a [[Function|function]].
== Syntax ==


== Usage ==
In [[:Category:Operation Flashpoint|{{ofp}}]], scripts are limited to [[SQS Syntax]].
* See [[exec]]


Scripts are mainly used for any game processes where '''timing''' is important. They are different to [[Function|functions]] where the ''result'' or ''calculation'' is important.
The already existing (since {{ofp}} v1.85) [[SQF Syntax]] was introduced for scripts in [[:Category:ArmA: Armed Assault|{{arma1}}]]. [[SQS Syntax]] is still usable but is considered deprecated since.
* See [[execVM]], [[spawn]]


Thus scripts can be used for cutscenes, dialogs, radio scripting and much more.


== Syntax ==
[[Image: Script_Execution.png|frame|right||Script Execution Diagram<br>'''Executing Instance:''' script, [[Function|function]] or game engine]]
 
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 ==
== Execution ==
Line 23: Line 21:
* Other scripts
* Other scripts
* Other [[Function|functions]]
* Other [[Function|functions]]
* Scripting lines in the [[Mission Editor]]
* Init fields and (de)activation triggers in the [[Mission Editor]]
* [[Event Handlers]] in addon config files
* [[:Category:Event Handlers|Event Handlers]] in addon config files
 


The commands to execute scripts are:
The commands to execute scripts are:


* FILL IN
; exec
 
: [[exec]] starts a thread for a script in [[SQS Syntax]].
Scripts are running ''besides'' the executing instance. 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]].


Since [[Armed Assault]], scripts return a [[Script (Handle)|script handle]] which you can use to verify whether a script is still running.
; execVM
: [[execVM]] [[preprocessFileLineNumbers|preprocesses]] and [[compile|compiles]] a [[SQF Syntax]] script file and starts a thread for it.


== Special Variables ==
; call
: [[call]] adds provided [[Code]] to the stack and wait for it to execute, then returns the code's last returned value.


_time in both syntax ?
; spawn
: [[spawn]] starts a thread for provided [[Code]].


== Special Commands ==
{{Feature | Informative |
* [[execVM]] is almost like using {{ic|[[spawn]] [[compile]] [[preprocessFile]]}}.
* [[spawn]] and [[execVM]] both add the thread to the [[Scheduler]] and provide a [[Script Handle|script handle]] which allows you to check if the spawned script is done (using [[scriptDone]]).}}


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]] 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]].
COMMAND 1;
// wait 10 seconds
sleep 10;
COMMAND 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;
COMMAND;
=== SQS syntax ===
; Delay
: You can set the script to sleep for a number of seconds by introducing a line with <tt>~</tt>, followed by the number of seconds.
COMMAND 1
; wait 10 seconds
~10
COMMAND 2
; Waiting for a condition
: You can set the script to sleep until a condition is met by introducing a line with <tt>@</tt>, followed by the condition.
BOOL = false
; wait until BOOL gets true
@BOOL
COMMAND
; 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 <tt>&</tt>, followed by the time.
&100
; is equivalent to
@_time >= 100


== See also ==
== See also ==


* [[Function|Functions]]
* [[Function|Functions]]
* [[SQF syntax]]
* [[:Category:Syntax|Syntax]]
* [[SQS syntax]]
** [[SQF Syntax]]
** [[SQS Syntax]]
* [[Statement]]
 


[[Category:Scripting Topics]]
[[Category:Scripting Topics]]
[[Category:ArmA: Scripting]]

Revision as of 19:18, 28 August 2021

A script file is multiple commands and arguments defining wanted behaviour from the game, all grouped together in a textfile. This code does a specific task handled by the game engine. The common extensions for Arma scripts are .sqf and .sqs, depending on the used syntax: SQF or (deprecated) SQS Syntax.

See Community Tools - Code Edition for recommended text editors.


Syntax

In Operation Flashpoint, scripts are limited to SQS Syntax.

The already existing (since Operation Flashpoint v1.85) SQF Syntax was introduced for scripts in Armed Assault. SQS Syntax is still usable but is considered deprecated since.


Script Execution Diagram
Executing Instance: script, function or game engine

Execution

Scripts can be executed from several points in the game:


The commands to execute scripts are:

exec
exec starts a thread for a script in SQS Syntax.
execVM
execVM preprocesses and compiles a SQF Syntax script file and starts a thread for it.
call
call adds provided Code to the stack and wait for it to execute, then returns the code's last returned value.
spawn
spawn starts a thread for provided Code.


See also