SQS to SQF conversion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Added category.)
m (Fix examples)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==What's different in SQF==
__NOEDITSECTION__
* Every command has to end with semicolon.
{{TOC|side}}
* SQF does not have a [[goto]] command anymore.
[[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 commands can span several lines if they are enclosed in brackets.
* SQF can return a variable, where SQS cannot.


==Replacing==
* '''[[execVM]]''' is used (instead of [[exec]] for SQS)
* Every command has to end with a semicolon (<sqf inline>;</sqf>)
* the following commands disappeared:
** [[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]]
* Line returns do not impact code
* SQF can return a variable, where SQS cannot


===Comment===
{{Box_File|SQS|
; This is a comment
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
// This is single-line comment


/* This is multiline
== Conversion examples ==
    comment
*/


comment "And this is a comment working both in SQS and SQF";
{| class="wikitable"
}}
! <big>SQS</big>
! <big>SQF</big>
|-
! colspan="2" |
=== Comment ===
|-
| <sqs>; This is a comment</sqs>
<sqs notrim>


===Condition===
; This is a
{{Box_File|SQS|
; multiline
@CONDITION
; comment
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[waitUntil]] {CONDITION};
}}


===Delay===
</sqs>
{{Box_File|SQS|
<sqs>comment "this is a comment";</sqs>
~DELAY
<sqs>"this is a comment";</sqs>
}}
|
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
<sqf>// This is single-line comment</sqf>
  [[sleep]] DELAY;
<sqf>
}}
/*
This is a
multiline
comment
*/
</sqf>
<sqf>comment "this is a comment";</sqf>
<sqf>"this is a comment";</sqf>
|-
! colspan="2" |
=== Condition wait ===
|-
|
<sqs>@CONDITION</sqs>
<sqs>@ not alive player</sqs>
|
<sqf>waitUntil { CONDITION };</sqf>
<sqf>waitUntil { not alive player };</sqf>
|-
! colspan="2" |
=== Delay ===
|-
|
<sqs>~DELAY</sqs>
<sqs>~5</sqs>
|
<sqf>sleep DELAY;</sqf>
<sqf>sleep 5;</sqf>
|-
! colspan="2" |
=== Conditional command ===
|-
|
<sqs>? CONDITION : COMMAND</sqs>
<sqs>? alive player : player setDammage 1</sqs>
|
<sqf>if (CONDITION) then { COMMAND };</sqf>
<sqf>if (alive player) then { player setDammage 1 };</sqf>
|-
! colspan="2" |
=== Multi-conditional command ===
|-
|
<sqs notrim>
? CONDITION : goto "SKIP"
COMMAND_2
goto "END"
#SKIP
  COMMAND_1
#END


===Conditional command===
{{Box_File|SQS|
?CONDITION: COMMAND
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[if]] (CONDITION) [[then]] {COMMAND};
}}


===Multi-conditional command===
</sqs>
{{Box_File|SQS|
|
?CONDITION: [[goto]] "SKIP"
<sqf>
  COMMAND_2
if (CONDITION) then
  [[goto]] "END"
{
#SKIP
COMMAND_1
  COMMAND_1
}
#END
else
}}
{
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
COMMAND_2
[[if]] (CONDITION) then {COMMAND_1} else {COMMAND_2};
};
}}
</sqf>
|-
! colspan="2" |
=== Cycle ===
|-
| <sqs>
#loop
COMMAND
~DELAY
? CONDITION : goto "LOOP"
</sqs>
|
<sqf>
while { CONDITION } do {
COMMAND;
sleep DELAY;
};
</sqf>
|-
! colspan="2" |
=== Cycle with step ===
|-
| <sqs>
_i = 0
#LOOP
COMMAND
_i = _i + 1;
? _i < COUNT : goto "LOOP"
</sqs>
| <sqf notrim>
for "_i" from 0 to COUNT -1 do {
COMMAND;
};


===Cycle===
{{Box_File|SQS|
#loop
  COMMAND
  ~DELAY
?CONDITION: [[goto]] "LOOP"
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[while]] {CONDITION} [[do]] {
  COMMAND;
  [[sleep]] DELAY;
};
}}


===Cycle with step===
</sqf>
{{Box_File|SQS|
|-
_n <nowiki>=</nowiki> 0
! colspan="2" |
  #LOOP
=== Structured conditional command ===
  COMMAND
|-
  _n <nowiki>=</nowiki> _n + 1;
| <sqs>
?_n < COUNT: [[goto]] "LOOP"
? VARIABLE == VALUE_1: goto "SKIP_1"
}}
? VARIABLE == VALUE_2: goto "SKIP_2"
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
DEFAULT_COMMAND
for [{_n <nowiki>=</nowiki> 0},{_n <<nowiki>=</nowiki> COUNT},{_n <nowiki>=</nowiki> _n+1}] do {
goto "END"
  COMMAND;
#SKIP_1
};
COMMAND_1
}}
  goto "END"
#SKIP_2
COMMAND_2
#END
</sqs>
| <sqf>
switch (VARIABLE) do
{
case VALUE_1:
{ COMMAND_1 };
case VALUE_2:
{ COMMAND_2 };
default
{ DEFAULT_COMMAND };
};
</sqf>
|-
! colspan="2" |
=== Exiting ===
|-
| <sqs>
? CONDITION : COMMAND_2
? CONDITION : exit
COMMAND_1
</sqs>
| <sqf notrim>
if (CONDITION) exitWith { COMMAND_2; };
COMMAND_1;


===Structured conditional command===
</sqf>
{{Box_File|SQS|
|}
?VARIABLE <nowiki>==</nowiki> VALUE_1: [[goto]] "SKIP_1"
?VARIABLE <nowiki>==</nowiki> VALUE_2: [[goto]] "SKIP_2"
  DEFAULT COMMAND
  [[goto]] "END"
#SKIP_1
  COMMAND_1
  goto "END"
#SKIP_2
  COMMAND_2
#END
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[switch]] (VARIABLE) [[do]] {
  [[case]] VALUE_1: {COMMAND_1};
  [[case]] VALUE_2: {COMMAND_2};
  [[default]] {DEFAULT_COMMAND};
};
}}


===Exiting===
{{Box_File|SQS|
?CONDITION: [[goto]] "Exit"
  COMMAND_1


#Exit
== See Also ==
  COMMAND_2
  exit
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[if]] (CONDITION) [[exitWith]]
{
  COMMAND_2;
};
COMMAND_1;
}}


== See Also ==
* [[SQF Syntax]]
* [[SQS Syntax]]
* [[Introduction to Arma Scripting]]


* [[SQF syntax]]
* [http://seit.unsw.adfa.edu.au/coursework/ZEIT2305/Resources/SQF_Tutorial/basic_sqf.HTML The basics of SQF]


[[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