SQS to SQF conversion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Fix intro and formatting)
m (Fix examples)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOEDITSECTION__
__NOEDITSECTION__
{{SideTOC}}
{{TOC|side}}
[[SQF syntax]] has been introduced in {{ofpr}} v1.85 and is the Arma series' main scripting language since. The main differences with [[SQS syntax]] are:
[[SQF Syntax]] has been introduced in {{ofpr}} v1.85 and is the Arma series' main scripting language since. The main differences with [[SQS Syntax]] are:


* '''[[execVM]]''' is used (instead of [[exec]] for SQS)
* '''[[execVM]]''' is used (instead of [[exec]] for SQS)
* Every command has to end with a semicolon ({{Inline code|;}})
* Every command has to end with a semicolon (<sqf inline>;</sqf>)
* the following commands disappeared:
* the following commands disappeared:
** [[goto]]/#label (Note, [[a hash b|#]] is a command in itself in {{arma3}})
** [[goto]]/[[SQS Syntax#Label|#label]] (Note, [[a hash b|#]] is a command in itself in {{arma3}})
** [[exit]] - a partial SQF equivalent can be found in [[exitWith]]
** [[exit]] - a partial SQF equivalent can be found in [[exitWith]]
* Line returns do not impact code
* Line returns do not impact code
* SQF can return a variable, where SQS cannot
* SQF can return a variable, where SQS cannot


== Conversion examples ==
== Conversion examples ==
Line 20: Line 21:
=== Comment ===
=== Comment ===
|-
|-
|
| <sqs>; This is a comment</sqs>
; This is a comment
<sqs notrim>


<code><nowiki>
; This is a
; This is a
; multiline
; multiline
; comment
; comment
</nowiki></code>
comment "this is a comment";


"this is a comment";
</sqs>
<sqs>comment "this is a comment";</sqs>
<sqs>"this is a comment";</sqs>
|
|
// This is single-line comment
<sqf>// This is single-line comment</sqf>
 
<sqf>
/*
/*
This is a
This is a
multiline
multiline
comment
comment
*/
*/
 
</sqf>
comment "this is a comment";
<sqf>comment "this is a comment";</sqf>
 
<sqf>"this is a comment";</sqf>
"this is a comment";
|-
|-
! colspan="2" |
! colspan="2" |
Line 50: Line 47:
|-
|-
|
|
@CONDITION
<sqs>@CONDITION</sqs>
 
<sqs>@ not alive player</sqs>
@ not alive player
|
|
[[waitUntil]] { CONDITION };
<sqf>waitUntil { CONDITION };</sqf>
 
<sqf>waitUntil { not alive player };</sqf>
[[waitUntil]] { not alive player };
|-
|-
! colspan="2" |
! colspan="2" |
Line 62: Line 57:
|-
|-
|
|
~DELAY
<sqs>~DELAY</sqs>
 
<sqs>~5</sqs>
~5
|
|
[[sleep]] DELAY;
<sqf>sleep DELAY;</sqf>
 
<sqf>sleep 5;</sqf>
[[sleep]] 5;
|-
|-
! colspan="2" |
! colspan="2" |
Line 74: Line 67:
|-
|-
|
|
? CONDITION : COMMAND
<sqs>? CONDITION : COMMAND</sqs>
 
<sqs>? alive player : player setDammage 1</sqs>
? alive player : player setDammage 1
|
|
[[if]] (CONDITION) [[then]] { COMMAND };
<sqf>if (CONDITION) then { COMMAND };</sqf>
 
<sqf>if (alive player) then { player setDammage 1 };</sqf>
[[if]] (alive player) [[then]] { player setDammage 1 };
|-
|-
! colspan="2" |
! colspan="2" |
===Multi-conditional command===
=== Multi-conditional command ===
|-
|-
|
|
? CONDITION : [[goto]] "SKIP"
<sqs notrim>
  COMMAND_2
? CONDITION : goto "SKIP"
  [[goto]] "END"
COMMAND_2
#SKIP
goto "END"
  COMMAND_1
#SKIP
COMMAND_1
  #END
  #END
</sqs>
|
|
[[if]] (CONDITION) [[then]] {
<sqf>
COMMAND_1
if (CONDITION) then
} [[else]] {
{
COMMAND_2
COMMAND_1
};
}
else
{
COMMAND_2
};
</sqf>
|-
|-
! colspan="2" |
! colspan="2" |
=== Cycle ===
=== Cycle ===
|-
|-
| <sqs>
#loop
COMMAND
~DELAY
? CONDITION : goto "LOOP"
</sqs>
|
|
#loop
<sqf>
  COMMAND
while { CONDITION } do {
  ~DELAY
COMMAND;
? CONDITION : [[goto]] "LOOP"
sleep DELAY;
|
};
[[while]] {CONDITION} [[do]] {
</sqf>
COMMAND;
[[sleep]] DELAY;
};
|-
|-
! colspan="2" |
! colspan="2" |
=== Cycle with step ===
=== Cycle with step ===
|-
|-
|
| <sqs>
_i = 0
_i = 0
#LOOP
#LOOP
  COMMAND
COMMAND
  _i = _i + 1;
_i = _i + 1;
? _i < COUNT : [[goto]] "LOOP"
? _i < COUNT : goto "LOOP"
|
</sqs>
[[for]] "_i" [[from]] 0 [[to]] COUNT -1 [[do]] {
| <sqf notrim>
COMMAND;
for "_i" from 0 to COUNT -1 do {
};
COMMAND;
};
 
 
</sqf>
|-
|-
! colspan="2" |
! colspan="2" |
=== Structured conditional command ===
=== Structured conditional command ===
|-
|-
|
| <sqs>
? VARIABLE == VALUE_1: [[goto]] "SKIP_1"
? VARIABLE == VALUE_1: goto "SKIP_1"
? VARIABLE == VALUE_2: [[goto]] "SKIP_2"
? VARIABLE == VALUE_2: goto "SKIP_2"
  DEFAULT_COMMAND
DEFAULT_COMMAND
  [[goto]] "END"
goto "END"
#SKIP_1
#SKIP_1
  COMMAND_1
COMMAND_1
  goto "END"
goto "END"
#SKIP_2
#SKIP_2
  COMMAND_2
COMMAND_2
#END
#END
|
</sqs>
[[switch]] (VARIABLE) [[do]] {
| <sqf>
[[case]] VALUE_1:
switch (VARIABLE) do
{ COMMAND_1 };
{
[[case]] VALUE_2:
case VALUE_1:
{ COMMAND_2 };
{ COMMAND_1 };
[[default]]
case VALUE_2:
{ DEFAULT_COMMAND };
{ COMMAND_2 };
};
default
   
{ DEFAULT_COMMAND };
};
  </sqf>
|-
|-
! colspan="2" |
! colspan="2" |
=== Exiting ===
=== Exiting ===
|-
|-
|
| <sqs>
? CONDITION : COMMAND_2
? CONDITION : COMMAND_2
? CONDITION : exit
? CONDITION : exit
  COMMAND_1
COMMAND_1
|
</sqs>
[[if]] (CONDITION) [[exitWith]] { COMMAND_2; };
| <sqf notrim>
COMMAND_1;
if (CONDITION) exitWith { COMMAND_2; };
COMMAND_1;
 
</sqf>
|}
|}


Line 172: Line 179:
== See Also ==
== See Also ==


* [[SQF syntax]]
* [[SQF Syntax]]
* [[SQS Syntax]]
* [[Introduction to Arma Scripting]]




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

Latest revision as of 21:40, 21 July 2022

SQF Syntax has been introduced in Operation Flashpoint: Resistance v1.85 and is the Arma series' main scripting language since. The main differences with SQS Syntax are:

  • execVM is used (instead of exec for SQS)
  • Every command has to end with a semicolon (;)
  • the following commands disappeared:
  • Line returns do not impact code
  • SQF can return a variable, where SQS cannot


Conversion examples

SQS SQF

Comment

; This is a comment

; This is a ; multiline ; comment
comment "this is a comment";
"this is a comment";

// This is single-line comment
/* This is a multiline comment */
comment "this is a comment";
"this is a comment";

Condition wait

@CONDITION

waitUntil { CONDITION };

Delay

~DELAY
~5

sleep DELAY;

Conditional command

? CONDITION : COMMAND

if (CONDITION) then { COMMAND };

Multi-conditional command

? CONDITION : goto "SKIP" COMMAND_2 goto "END" #SKIP COMMAND_1 #END

if (CONDITION) then { COMMAND_1 } else { COMMAND_2 };

Cycle

#loop COMMAND ~DELAY ? CONDITION : goto "LOOP"

while { CONDITION } do { COMMAND; sleep DELAY; };

Cycle with step

_i = 0 #LOOP COMMAND _i = _i + 1; ? _i < COUNT : goto "LOOP"
for "_i" from 0 to COUNT -1 do { COMMAND; };

Structured conditional command

? VARIABLE == VALUE_1: goto "SKIP_1" ? VARIABLE == VALUE_2: goto "SKIP_2" DEFAULT_COMMAND goto "END" #SKIP_1 COMMAND_1 goto "END" #SKIP_2 COMMAND_2 #END
switch (VARIABLE) do { case VALUE_1: { COMMAND_1 }; case VALUE_2: { COMMAND_2 }; default { DEFAULT_COMMAND }; };

Exiting

? CONDITION : COMMAND_2 ? CONDITION : exit COMMAND_1
if (CONDITION) exitWith { COMMAND_2; }; COMMAND_1;


See Also