SQF Syntax: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Mentioned SQF meaning Status Quo Function)
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
'''SQF syntax''' was introduced in [[Operation Flashpoint: Resistance]] and is the common [[Syntax|syntax]] since [[Armed Assault]]. An alternative syntax is the [[SQS syntax]] (deprecated since Armed Assault).
[[SQF syntax]] (where SQF stands for Status Quo Function) was introduced in [[Operation Flashpoint: Resistance Version History|OFP: Resistance]] and is the common [[Syntax|syntax]] since [[Armed Assault]]. An alternative syntax is the [[SQS syntax]] (deprecated since Armed Assault).
 
While [[SQS syntax]] is line based, SQF syntax is based on structured expressions. End-of-line has no special meaning - it is considered to be equivalent to space or tab, and is therefore not required, even when ending a statement.


== Rules ==
== Rules ==
Line 7: Line 5:
Binding rules:
Binding rules:


* Curled braces group code to '''blocks'''
* Curled braces ({ }) group code to '''[[Block|blocks]]'''
* Commands and blocks are followed by '''semicolons'''
* [[Statement|Statements]] (thus also blocks) are followed by '''semicolons''' (;)


The latter rule tells the game engine where one command ends and the next starts.
The latter rule tells the game engine where one statement ends and the next starts.


Example:
Example:


  Command 1;
  STATEMENT 1;
  Command 2;
  STATEMENT 2;
   
   
  Block
  BLOCK
  {
  {
     Command 3;
     STATEMENT 3;
     Command 4;  
     STATEMENT 4;  
  };
  };


===Operation Flashpoint===
While [[SQS syntax]] is line based, SQF syntax is based on structured expressions. End-of-line has no special meaning - it is considered to be equivalent to space or tab, and is therefore not required, even when ending a statement.


SQF syntax was introduced for the first time with the [[call]] command in Operation Flashpoint. Usage was limited to execution of [[Function|functions]].
== Comments ==


===Armed Assault===
A comment is any free text which is ignored by the game engine. In SQF syntax you can write comments using the command [[comment]].


With the release of Armed Assault, the SQS syntax for scripting was deprecated. SQF syntax is expected to be used for both scripts and [[Function|functions]].
Example:
[[sqs syntax|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.
<br>


comment "This is a comment";


'''Diagram of Scripts Running in Parallel'''


[[Image:ParallelSQFScript.jpg]]
If a file is loaded with [[preprocessFile]], [[execVM]] or [[spawn]], you may also define C-like comments (does not work for [[loadFile]]):


<br>
; Line comment
'''Diagram of Scripts Running in Parallel using [[waitUntil]] and [[scriptDone]] to pause execution'''
: A line comment starts with <tt>//</tt> and makes the rest of the line a comment.


[[Image:ParallelSQFScript_WaitUntil.jpg]]
; Block comment
: A block comment starts with <tt>/*</tt> and ends with <tt>*/</tt>. All text in between is considered a comment.


<br>
Examples:


==Language Constructs==
// This is a line comment
/*
This is
a very long
block comment
*/


Main language contructs used in functions are:
== Language Constructs ==
*[[if]]..[[then]]..[[else]]
*[[while]]..[[do]]
* since [[ArmA]]: [[for]] ... [[from]] ... [[to]] ... [[step]]
* since [[ArmA]]: [[switch]] ... [[do]]
*Curled braces '''{ }'''
*Multiple commands (including assigment commands) are delimited with a semicolon.


==Notes==
Read the article [[Control Structures]] for information about the control structures available in SQF syntax.
Due to line-based nature of [[sqs syntax|Sqs scripts]] it is not possible to create multiline string constants in them.<br>
To overcome this limitation you can store multiline in separate SQF [[Function|function]] files and load them using [[loadFile]] or [[preprocessFile]] (the second uses C-like preprocessor with // or /* */ comments and #define macros).<br>


==See also==
== See also ==
[[:Category:Scripting Commands|Commands]]
*[[call (ArmA)|call]]
*[[execVM]]
*[[spawn]]


[[Function]]
* [[SQS syntax]]
* [[Function]]
* [[Statement]]
* [[Block]]
* [[Missions#Locations_of_Mission_Files|Location of script files]]
* [[SQS to SQF conversion]]


[[Category: Scripting_Topics]]
[[Category: Syntax]]
[[Category:Scripting Topics]]

Revision as of 19:21, 29 April 2015

SQF syntax (where SQF stands for Status Quo Function) was introduced in OFP: Resistance and is the common syntax since Armed Assault. An alternative syntax is the SQS syntax (deprecated since Armed Assault).

Rules

Binding rules:

  • Curled braces ({ }) group code to blocks
  • Statements (thus also blocks) are followed by semicolons (;)

The latter rule tells the game engine where one statement ends and the next starts.

Example:

STATEMENT 1;
STATEMENT 2;

BLOCK
{
    STATEMENT 3;
    STATEMENT 4; 
};

While SQS syntax is line based, SQF syntax is based on structured expressions. End-of-line has no special meaning - it is considered to be equivalent to space or tab, and is therefore not required, even when ending a statement.

Comments

A comment is any free text which is ignored by the game engine. In SQF syntax you can write comments using the command comment.

Example:

comment "This is a comment";


If a file is loaded with preprocessFile, execVM or spawn, you may also define C-like comments (does not work for loadFile):

Line comment
A line comment starts with // and makes the rest of the line a comment.
Block comment
A block comment starts with /* and ends with */. All text in between is considered a comment.

Examples:

// This is a line comment

/*
This is
a very long
block comment
*/

Language Constructs

Read the article Control Structures for information about the control structures available in SQF syntax.

See also