SQS Syntax: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Some wiki formatting)
 
(24 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{tool-disclaimer
{{TOC|side|1|}}
| <center>Disclaimer: SQS script syntax is considered deprecated</center>
[[SQS Syntax]] (where SQS stands for Status Quo Script) was the main [[Syntax|syntax]] in [[:Category:Operation Flashpoint|{{ofp}}]] and is still available (although considered obsolete) in later titles. It can only be used for [[Script File|scripts]], but not for [[Function|functions]], in the [[Mission Editor]] or in addon config files. The newer script syntax is [[SQF Syntax]].
| <center>When creating scripts for [[Armed Assault]] or newer products, use [[SQF syntax]] where possible.</center>
}}


'''SQS syntax''' was the main [[Syntax|syntax]] in [[Operation Flashpoint]] and is still available in [[Armed Assault]]. It can only be used for [[Script (File)|scripts]], but not for [[Function|functions]], in the [[Mission Editor]] or in addon config files. The alternative syntax is [[SQF syntax]].


== Rules ==
== Rules ==
Line 10: Line 7:
Binding rules:
Binding rules:


* Commands are seperated by '''line breaks''' ''and'' '''semicolons''' (;). This means that a [[Statement|statement]] ''must not'' span over multiple lines.
* [[Statement|Statements]] are separated by '''line breaks''', '''semicolons''' (;) and '''commas''' (,) - this means that a statement ''can not'' span over multiple lines (e.g a [[switch]] usage must be all inlined).
* Curled braces ({ }) group code to '''blocks'''. A block is considered a single statement, thus may not span over multiple lines.
* A [[Code|code block]] (defined by curled braces <sqs inline>{ }</sqs>) is considered a single statement, thus may not span over multiple lines either.


Example:
=== Example ===


  STATEMENT 1
  STATEMENT 1
  STATEMENT 2; STATEMENT 3
  STATEMENT 2; STATEMENT 3, STATEMENT 4
   
   
  BLOCK { STATEMENT 4; STATEMENT 5 }
  BLOCK { STATEMENT 5; STATEMENT 6 }
 


== Comments ==
== Comments ==


A line beginning with a '''semicolon''' (;) is considered a comment and ignored by the game engine.
A line beginning with a '''semicolon''' ({{hl|;}}) is considered a comment and ignored by the game engine.


Example:
=== Example ===
 
<sqs>; this is my comment</sqs>


; this is my comment


== Language Constructs ==
== Language Constructs ==
Line 32: Line 31:
The control structures listed in the article [[Control Structures]] may also be used in SQS syntax. Note that they must be written '''within a single line''' due to the above rules.
The control structures listed in the article [[Control Structures]] may also be used in SQS syntax. Note that they must be written '''within a single line''' due to the above rules.


There exist also special structures limited to SQS syntax.
; Example
<sqs>if (_value == 1) then { hint "Value is 1" } else { hint "Value is not 1" }</sqs>
 
There exist also special structures limited to SQS syntax, listed below.
 
=== Tilde ===
 
The tilde ({{hl|~}}) symbol tells the script to wait X amount of seconds (see [[sleep]] in SQF):
 
<sqs>
hint "3..."
~1
hint "2..."
~1
hint "1..."
~1
hint "GO!"
</sqs>


=== Label ===
=== Label ===


You may define labels in the code by beginning a line with <tt>#</tt>, followed by the name of the label (without spaces). You may use the command [[goto]] at any point of the [[Script (File)|script]] to jump to this label.
Labels may be defined in the code by beginning a line with {{hl|#}}, followed by the label's name (without spaces).
The [[goto]] command can then be used at any point of the [[Script File|script]] to jump to this label (and potentially create a loop).


#Label1
<sqs>
#Label1
CODE
 
~1
goto "Label1"
hint format ["a second has passed. time: %1", round time]
 
goto "Label1"
</sqs>


=== Conditional ===
=== Conditional ===


You may query a [[Boolean]] condition and define code, that is executed ''only'' when the condition is <tt>true</tt>. Note that there is no equivalent for "else". A conditional line must start with <tt>?</tt>, followed by the condition and <tt>:</tt>, followed by one or more commands. Multiple commands  are seperated by commas (,) or semicolons (;).
A [[Boolean]] condition can be used in order to run code that is executed ''only'' when said condition is {{hl|[[true]]}}. Note that there is no such equivalent for "[[else]]".
A conditional line must start with {{hl|?}}, followed by the condition and {{hl|:}}, followed by one or more commands. Multiple commands  are separated by commas (,) or semicolons (;).
The conditional statement, like other statements, ends with the end of the line.
 
<sqs>? alive target : hint "target is alive, let's destroy it"; target setDammage 1</sqs>
 
=== @ ===
 
Much like the [[waitUntil]] statement in [[SQF Syntax]], @ will evaluate a certain condition, and the script will pause until @ returns [[true]].
 
<sqs>@not alive target</sqs>


? CONDITION : COMMAND 1; COMMAND 2


== Notes ==
== Notes ==


Due to line-based nature of [[sqs syntax|Sqs scripts]] it is not possible to create multiline string constants in them. 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).
Due to the line-based nature of [[SQS Syntax|SQS scripts]], it is not possible to create multiline string constants in them.
To overcome this limitation multiline text can be stored in a separate text file and loaded using [[loadFile]] or [[preprocessFile]] (the second uses C-like preprocessor with // or /* */ comments and #define macros).
 
 
== Limitations ==
 
In {{GameCategory|ofp|link= y}}, if a single line of a sqs file is longer than 4096 characters, the game will return an error and will not execute the line.
 


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


* [[SQF syntax]]
* [[SQF Syntax]]
* [[Script (File)]]
* [[Script File]]
* [[Statement]]
* [[Block]]
 


[[Category: Scripting_Topics ]]
[[Category: Syntax]]
[[Category: ArmA: Scripting]]

Latest revision as of 21:27, 2 September 2022

SQS Syntax (where SQS stands for Status Quo Script) was the main syntax in Operation Flashpoint and is still available (although considered obsolete) in later titles. It can only be used for scripts, but not for functions, in the Mission Editor or in addon config files. The newer script syntax is SQF Syntax.


Rules

Binding rules:

  • Statements are separated by line breaks, semicolons (;) and commas (,) - this means that a statement can not span over multiple lines (e.g a switch usage must be all inlined).
  • A code block (defined by curled braces { }) is considered a single statement, thus may not span over multiple lines either.

Example

STATEMENT 1
STATEMENT 2; STATEMENT 3, STATEMENT 4

BLOCK { STATEMENT 5; STATEMENT 6 }


Comments

A line beginning with a semicolon (

) is considered a comment and ignored by the game engine.

Example

; this is my comment


Language Constructs

The control structures listed in the article Control Structures may also be used in SQS syntax. Note that they must be written within a single line due to the above rules.

Example

if (_value == 1) then { hint "Value is 1" } else { hint "Value is not 1" }

There exist also special structures limited to SQS syntax, listed below.

Tilde

The tilde (~) symbol tells the script to wait X amount of seconds (see sleep in SQF):

hint "3..." ~1 hint "2..." ~1 hint "1..." ~1 hint "GO!"

Label

Labels may be defined in the code by beginning a line with #, followed by the label's name (without spaces). The goto command can then be used at any point of the script to jump to this label (and potentially create a loop).

#Label1 ~1 hint format ["a second has passed. time: %1", round time] goto "Label1"

Conditional

A Boolean condition can be used in order to run code that is executed only when said condition is true. Note that there is no such equivalent for "else". A conditional line must start with ?, followed by the condition and :, followed by one or more commands. Multiple commands are separated by commas (,) or semicolons (;). The conditional statement, like other statements, ends with the end of the line.

? alive target : hint "target is alive, let's destroy it"; target setDammage 1

@

Much like the waitUntil statement in SQF Syntax, @ will evaluate a certain condition, and the script will pause until @ returns true.

@not alive target


Notes

Due to the line-based nature of SQS scripts, it is not possible to create multiline string constants in them. To overcome this limitation multiline text can be stored in a separate text file and loaded using loadFile or preprocessFile (the second uses C-like preprocessor with // or /* */ comments and #define macros).


Limitations

In Operation Flashpoint, if a single line of a sqs file is longer than 4096 characters, the game will return an error and will not execute the line.


See also