SQS to SQF conversion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Removed old link)
(Fix intro and formatting)
Line 1: Line 1:
==What's different in SQF==
__NOEDITSECTION__
* Every command has to end with semicolon.
{{SideTOC}}
* 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 ({{Inline code|;}})
* the following commands disappeared:
** [[goto]]/#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===
== Conversion examples ==
{{Box_File|SQS|
 
{| class="wikitable"
! <big>SQS</big>
! <big>SQF</big>
|-
! colspan="2" |
=== Comment ===
|-
|
  ; This is a comment
  ; This is a comment
}}
 
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
<code><nowiki>
; This is a
; multiline
; comment
</nowiki></code>
 
comment "this is a comment";
 
"this is a comment";
|
  // This is single-line comment
  // This is single-line comment


  /* This is multiline
  /*
    comment
This is a
multiline
comment
  */
  */


  comment "And this is a comment working both in SQS and SQF";
  comment "this is a comment";
}}


===Condition===
"this is a comment";
{{Box_File|SQS|
|-
! colspan="2" |
=== Condition wait ===
|-
|
  @CONDITION
  @CONDITION
}}
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
[[waitUntil]] {CONDITION};
}}


===Delay===
@ not alive player
{{Box_File|SQS|
|
[[waitUntil]] { CONDITION };
 
[[waitUntil]] { not alive player };
|-
! colspan="2" |
=== Delay ===
|-
|
  ~DELAY
  ~DELAY
}}
 
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
~5
|
  [[sleep]] DELAY;
  [[sleep]] DELAY;
}}


===Conditional command===
[[sleep]] 5;
{{Box_File|SQS|
|-
  ?CONDITION: COMMAND
! colspan="2" |
}}
=== Conditional command ===
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
|-
  [[if]] (CONDITION) [[then]] {COMMAND};
|
}}
  ? CONDITION : COMMAND
 
? alive player : player setDammage 1
|
  [[if]] (CONDITION) [[then]] { COMMAND };


[[if]] (alive player) [[then]] { player setDammage 1 };
|-
! colspan="2" |
===Multi-conditional command===
===Multi-conditional command===
{{Box_File|SQS|
|-
  ?CONDITION: [[goto]] "SKIP"
|
  ? CONDITION : [[goto]] "SKIP"
   COMMAND_2
   COMMAND_2
   [[goto]] "END"
   [[goto]] "END"
Line 53: Line 92:
   COMMAND_1
   COMMAND_1
  #END
  #END
}}
|
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
  [[if]] (CONDITION) [[then]] {
  [[if]] (CONDITION) then {COMMAND_1} else {COMMAND_2};
COMMAND_1
}}
} [[else]] {
 
COMMAND_2
===Cycle===
};
{{Box_File|SQS|
|-
! colspan="2" |
=== Cycle ===
|-
|
  #loop
  #loop
   COMMAND
   COMMAND
   ~DELAY
   ~DELAY
  ?CONDITION: [[goto]] "LOOP"
  ? CONDITION : [[goto]] "LOOP"
}}
|
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
  [[while]] {CONDITION} [[do]] {
  [[while]] {CONDITION} [[do]] {
  COMMAND;
COMMAND;
  [[sleep]] DELAY;
[[sleep]] DELAY;
  };
  };
}}
|-
 
! colspan="2" |
===Cycle with step===
=== Cycle with step ===
{{Box_File|SQS|
|-
  _n <nowiki>=</nowiki> 0
|
  _i = 0
  #LOOP
  #LOOP
   COMMAND
   COMMAND
   _n <nowiki>=</nowiki> _n + 1;
   _i = _i + 1;
  ?_n < COUNT: [[goto]] "LOOP"
  ? _i < COUNT : [[goto]] "LOOP"
}}
|
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
  [[for]] "_i" [[from]] 0 [[to]] COUNT -1 [[do]] {
  for [{_n <nowiki>=</nowiki> 0},{_n <<nowiki>=</nowiki> COUNT},{_n <nowiki>=</nowiki> _n+1}] do {
COMMAND;
  COMMAND;
  };
  };
}}
 
===Structured conditional command===
|-
{{Box_File|SQS|
! colspan="2" |
  ?VARIABLE <nowiki>==</nowiki> VALUE_1: [[goto]] "SKIP_1"
=== Structured conditional command ===
  ?VARIABLE <nowiki>==</nowiki> VALUE_2: [[goto]] "SKIP_2"
|-
   DEFAULT COMMAND
|
  ? VARIABLE == VALUE_1: [[goto]] "SKIP_1"
  ? VARIABLE == VALUE_2: [[goto]] "SKIP_2"
   DEFAULT_COMMAND
   [[goto]] "END"
   [[goto]] "END"
  #SKIP_1
  #SKIP_1
Line 98: Line 144:
   COMMAND_2
   COMMAND_2
  #END
  #END
}}
|
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
  [[switch]] (VARIABLE) [[do]] {
  [[switch]] (VARIABLE) [[do]] {
  [[case]] VALUE_1: {COMMAND_1};
[[case]] VALUE_1:
  [[case]] VALUE_2: {COMMAND_2};
{ COMMAND_1 };
  [[default]] {DEFAULT_COMMAND};
[[case]] VALUE_2:
{ COMMAND_2 };
[[default]]
{ DEFAULT_COMMAND };
  };
  };
}}
 
===Exiting===
|-
{{Box_File|SQS|
! colspan="2" |
  ?CONDITION: [[goto]] "Exit"
=== Exiting ===
|-
|
  ? CONDITION : COMMAND_2
? CONDITION : exit
   COMMAND_1
   COMMAND_1
|
[[if]] (CONDITION) [[exitWith]] { COMMAND_2; };
COMMAND_1;
|}


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


== See Also ==
== See Also ==


* [[SQF syntax]]
* [[SQF syntax]]


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

Revision as of 03:10, 30 January 2020

Template:SideTOC 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:
    • goto/#label (Note, # is a command in itself in Arma 3)
    • exit - a partial SQF equivalent can be found in exitWith
  • 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
@ not alive player
waitUntil { CONDITION };
waitUntil { not alive player };

Delay

~DELAY
~5
sleep DELAY;
sleep 5;

Conditional command

? CONDITION : COMMAND
? alive player : player setDammage 1
if (CONDITION) then { COMMAND };
if (alive player) then { player setDammage 1 };

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