SQS Syntax: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (SQS Syntax moved to SQS syntax)
m (Some wiki formatting)
 
(33 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{SQS-disclaimer}}
{{TOC|side|1|}}
'''Description:'''
[[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]].


SQS Syntax is a scripting syntax which is executed in a line-by-line nature. Because each line is compiled and executed individually, performance is typically less than that of scripts which are compiled prior to execution such as with code written in the [[sqf syntax]]. 


Each script line may be one of the following:
== Rules ==


Binding rules:


'''Comment:''' Line starting with '''';''''.<br>
* [[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).
'''''Example:'''''  
* A [[Code|code block]] (defined by curled braces <sqs inline>{ }</sqs>) is considered a single statement, thus may not span over multiple lines either.
''';'''This is a comment


=== Example ===


'''Label:''' Line starting with ''''#''''.<br>
STATEMENT 1
'''''Example:'''''
STATEMENT 2; STATEMENT 3, STATEMENT 4
  '''#'''LabelName
   
See the [[goto]] command for more information on using a label in a script.
BLOCK { STATEMENT 5; STATEMENT 6 }




'''Waiting for a condition:''' Line starting with ''''@''''.<br>
== Comments ==
'''''Example:'''''
'''@'''condition


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


'''Waiting for a time:''' Line starting with ''''&''''.<br>
=== Example ===
'''''Example:'''''
'''&'''endTime......is equivalent to @_time >= (endTime)


<sqs>; this is my comment</sqs>


'''Delay:''' Line starting with ''''~''''.<br>
'''''Example:'''''
'''~'''delay......Is equivalent to __waitUntil = _time+(cas) ; &__waitUntil


== Language Constructs ==


'''Command:''' Any expression returning no value.<br>
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:'''''
_unit [[setBehaviour]] "safe"


See the [[Scripting|scripting]] command list for more information.
; Example
<sqs>if (_value == 1) then { hint "Value is 1" } else { hint "Value is not 1" }</sqs>


'''Assignment:''' Assignment of any value to a variable.<br>
There exist also special structures limited to SQS syntax, listed below.
'''''Example:'''''
_a = 10


=== Tilde ===


'''Conditional:''' ? condition......Command or assignment, command is executed only when condition is satisfied.<br>
The tilde ({{hl|~}}) symbol tells the script to wait X amount of seconds (see [[sleep]] in SQF):
'''''Example:'''''
? _condVar > 10: _var = _var + 2


<sqs>
hint "3..."
~1
hint "2..."
~1
hint "1..."
~1
hint "GO!"
</sqs>


'''[[Local_variables|Local]]''' variables can be used during script execution to avoid variable conflicts. [[Local_variables|Local]] variable names start with an underscore ('_'). <br>
=== Label ===
'''''Example:'''''
_varA would be a [[Local_variables|local]] variable
varA would be a global variable


'''Notes:'''
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).


Variable '''_time''' is reserved. It is used to keep the time elapsed since script execution started.
<sqs>
#Label1


Variables starting with two underscores are reserved and should never be used.
~1
hint format ["a second has passed. time: %1", round time]


A '''"[[Local_variables|local]]"''' variable means that the variable's scope is a certain script/function.
goto "Label1"
</sqs>


A "'''global'''" variable means that you can use this variable in any script on that machine.
=== Conditional ===


A "'''public'''" variable means that this variable has been broadcasted over the net and is available on every client. See [[publicVariable]] for more information.
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>


[[Category: Scripting_Topics ]]
=== @ ===
 
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>
 
 
== Notes ==
 
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 ==
 
* [[SQF Syntax]]
* [[Script File]]
* [[Statement]]
* [[Block]]
 
 
[[Category: Syntax]]

Latest revision as of 22: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