Difference between revisions of "SQS to SQF conversion"

From Bohemia Interactive Community
Jump to navigation Jump to search
(Article about difference between SQS and SQF. I'm not sure with headings (Command with condition, ...), so feel free to correct it.)
 
m (Removed old link)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
==What's different in SQF==
 
==What's different in SQF==
* Every command have to be ended with semicolon.
+
* Every command has to end with semicolon.
* Cycles are limited to 10 000 loops.
+
* SQF does not have a [[goto]] command anymore.
 +
* SQF commands can span several lines if they are enclosed in brackets.
 +
* SQF can return a variable, where SQS cannot.
 +
 
 
==Replacing==
 
==Replacing==
  
Line 15: Line 18:
 
  */
 
  */
  
  comment "And this is comment working both in SQS and SQF";
+
  comment "And this is a comment working both in SQS and SQF";
 
}}
 
}}
  
Line 34: Line 37:
 
}}
 
}}
  
===Command with condition===
+
===Conditional command===
 
{{Box_File|SQS|
 
{{Box_File|SQS|
 
  ?CONDITION: COMMAND
 
  ?CONDITION: COMMAND
Line 42: Line 45:
 
}}
 
}}
  
===Structured command with condition===
+
===Multi-conditional command===
 
{{Box_File|SQS|
 
{{Box_File|SQS|
 
  ?CONDITION: [[goto]] "SKIP"
 
  ?CONDITION: [[goto]] "SKIP"
COMMAND_2
+
  COMMAND_2
[[goto]] "END"
+
  [[goto]] "END"
 
  #SKIP
 
  #SKIP
COMMAND_1
+
  COMMAND_1
  "END"
+
  #END
 
}}
 
}}
 
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
 
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
Line 58: Line 61:
 
{{Box_File|SQS|
 
{{Box_File|SQS|
 
  #loop
 
  #loop
COMMAND
+
  COMMAND
~DELAY
+
  ~DELAY
 
  ?CONDITION: [[goto]] "LOOP"
 
  ?CONDITION: [[goto]] "LOOP"
 
}}
 
}}
Line 73: Line 76:
 
  _n <nowiki>=</nowiki> 0
 
  _n <nowiki>=</nowiki> 0
 
  #LOOP
 
  #LOOP
COMMAND
+
  COMMAND
_n <nowiki>=</nowiki> _n + 1;
+
  _n <nowiki>=</nowiki> _n + 1;
 
  ?_n < COUNT: [[goto]] "LOOP"
 
  ?_n < COUNT: [[goto]] "LOOP"
 
}}
 
}}
Line 83: Line 86:
 
}}
 
}}
  
===Structured command with conditions===
+
===Structured conditional command===
 
{{Box_File|SQS|
 
{{Box_File|SQS|
 
  ?VARIABLE <nowiki>==</nowiki> VALUE_1: [[goto]] "SKIP_1"
 
  ?VARIABLE <nowiki>==</nowiki> VALUE_1: [[goto]] "SKIP_1"
 
  ?VARIABLE <nowiki>==</nowiki> VALUE_2: [[goto]] "SKIP_2"
 
  ?VARIABLE <nowiki>==</nowiki> VALUE_2: [[goto]] "SKIP_2"
DEFAULT
+
  DEFAULT COMMAND
[[goto]] "END"
+
  [[goto]] "END"
 
  #SKIP_1
 
  #SKIP_1
COMMAND_1
+
  COMMAND_1
goto "konec"
+
  goto "END"
 
  #SKIP_2
 
  #SKIP_2
COMMAND_2
+
  COMMAND_2
 
  #END
 
  #END
 
}}
 
}}
Line 99: Line 102:
 
  [[switch]] (VARIABLE) [[do]] {
 
  [[switch]] (VARIABLE) [[do]] {
 
   [[case]] VALUE_1: {COMMAND_1};
 
   [[case]] VALUE_1: {COMMAND_1};
   [[case]] VALUE_2: {COMMAND_1};
+
   [[case]] VALUE_2: {COMMAND_2};
   [[default]] {DEFAULT};
+
   [[default]] {DEFAULT_COMMAND};
 +
};
 +
}}
 +
 
 +
===Exiting===
 +
{{Box_File|SQS|
 +
?CONDITION: [[goto]] "Exit"
 +
  COMMAND_1
 +
 
 +
#Exit
 +
  COMMAND_2
 +
  exit
 +
}}
 +
{{Box_File|SQF|color_dark=#78AF78|color_light=#f2fff2|
 +
[[if]] (CONDITION) [[exitWith]]
 +
{
 +
  COMMAND_2;
 
  };
 
  };
 +
COMMAND_1;
 
}}
 
}}
 +
 +
== See Also ==
 +
 +
* [[SQF syntax]]
  
 
[[Category:Syntax]]
 
[[Category:Syntax]]
 +
[[Category:Scripting Topics]]

Latest revision as of 15:51, 17 January 2018

What's different in SQF

  • Every command has to end with semicolon.
  • SQF does not have a goto command anymore.
  • SQF commands can span several lines if they are enclosed in brackets.
  • SQF can return a variable, where SQS cannot.

Replacing

Comment

SQS
; This is a comment
SQF
// This is single-line comment
/* This is multiline
   comment
*/
comment "And this is a comment working both in SQS and SQF";


Condition

SQS
@CONDITION
SQF
waitUntil {CONDITION};


Delay

SQS
~DELAY
SQF
sleep DELAY;


Conditional command

SQS
?CONDITION: COMMAND
SQF
if (CONDITION) then {COMMAND};


Multi-conditional command

SQS
?CONDITION: goto "SKIP"
 COMMAND_2
 goto "END"
#SKIP
 COMMAND_1
#END
SQF
if (CONDITION) then {COMMAND_1} else {COMMAND_2};


Cycle

SQS
#loop
 COMMAND
 ~DELAY
?CONDITION: goto "LOOP"
SQF
while {CONDITION} do {
 COMMAND;
 sleep DELAY;
};


Cycle with step

SQS
_n = 0
#LOOP
 COMMAND
 _n = _n + 1;
?_n < COUNT: goto "LOOP"
SQF
for [{_n = 0},{_n <= COUNT},{_n = _n+1}] do {
 COMMAND;
};


Structured conditional command

SQS
?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
SQF
switch (VARIABLE) do {
 case VALUE_1: {COMMAND_1};
 case VALUE_2: {COMMAND_2};
 default {DEFAULT_COMMAND};
};


Exiting

SQS
?CONDITION: goto "Exit"
 COMMAND_1
#Exit
 COMMAND_2
 exit
SQF
if (CONDITION) exitWith
{
 COMMAND_2;
};
COMMAND_1;


See Also