SQS Syntax: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (SQS Syntax moved to SQS syntax)
m (Mentioned SQS meaning Status Quo Script)
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{SQS-disclaimer}}
[[SQS syntax]] (where SQS stands for Status Quo Script) 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 [[ArmA: Mission Editor|Mission Editor]] or in addon config files. The alternative syntax is [[SQF syntax]].
'''Description:'''


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]]. 
== Rules ==


Each script line may be one of the following:
Binding rules:


* [[Statement|Statements]] are separated by '''line breaks''' ''and'' '''semicolons''' (;) ''and'' '''commas''' (,). This means that a statement ''must not'' span over multiple lines.
* Curled braces ({ }) group code to '''blocks'''. A block is considered a single statement, thus may not span over multiple lines.


'''Comment:''' Line starting with '''';''''.<br>
Example:
'''''Example:'''''
''';'''This is a comment


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


'''Label:''' Line starting with ''''#''''.<br>
== Comments ==
'''''Example:'''''
'''#'''LabelName
See the [[goto]] command for more information on using a label in a script.


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


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


; this is my comment


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


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.


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


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


'''Command:''' Any expression returning no value.<br>
There exist also special structures limited to SQS syntax.
'''''Example:'''''
_unit [[setBehaviour]] "safe"


See the [[Scripting|scripting]] command list for more information.
=== Label ===


'''Assignment:''' Assignment of any value to a variable.<br>
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.
'''''Example:'''''
_a = 10


#Label1
CODE
goto "Label1"


'''Conditional:''' ? condition......Command or assignment, command is executed only when condition is satisfied.<br>
=== Conditional ===
'''''Example:'''''
? _condVar > 10: _var = _var + 2


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 separated by commas (,) or semicolons (;). The conditional statement ends with the end of the line.


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


'''Notes:'''
=== @ ===


Variable '''_time''' is reserved. It is used to keep the time elapsed since script execution started.
Much like the [[waitUntil]] statement in [[SQF syntax]], @ will evaluate a certain condition, and the script will pause until @ returns true.


Variables starting with two underscores are reserved and should never be used.
@ CONDITION


A '''"[[Local_variables|local]]"''' variable means that the variable's scope is a certain script/function.
== Notes ==


A "'''global'''" variable means that you can use this variable in any script on that machine.
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).


A "'''public'''" variable means that this variable has been broadcasted over the net and is available on every client. See [[publicVariable]] for more information.
== Limitations ==


In '''OFP v1.96''', if a single line of a sqs file is longer than 4096 characters, OFP will return an error and will not execute the line.


[[Category: Scripting_Topics ]]
== See also ==
 
* [[SQF syntax]]
* [[Script (File)]]
* [[Statement]]
* [[Block]]
 
[[Category: Syntax]]

Revision as of 19:23, 29 April 2015

SQS syntax (where SQS stands for Status Quo Script) was the main syntax in Operation Flashpoint and is still available in Armed Assault. It can only be used for scripts, but not for functions, in the Mission Editor or in addon config files. The alternative syntax is SQF syntax.

Rules

Binding rules:

  • Statements are separated by line breaks and semicolons (;) and commas (,). This means that a statement must not span over multiple lines.
  • Curled braces ({ }) group code to blocks. A block is considered a single statement, thus may not span over multiple lines.

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.

Label

You may define labels in the code by beginning a line with #, followed by the name of the label (without spaces). You may use the command goto at any point of the script to jump to this label.

#Label1

CODE

goto "Label1"

Conditional

You may query a Boolean condition and define code, that is executed only when the condition is true. Note that there is no 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 ends with the end of the line.

? CONDITION : STATEMENT 1; STATEMENT 2

@

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

@ CONDITION

Notes

Due to line-based nature of 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 files and load them using loadFile or preprocessFile (the second uses C-like preprocessor with // or /* */ comments and #define macros).

Limitations

In OFP v1.96, if a single line of a sqs file is longer than 4096 characters, OFP will return an error and will not execute the line.

See also