SQS to SQF conversion: Difference between revisions
Jump to navigation
Jump to search
m (Text replacement - "{{Inline code|" to "{{ic|") |
Lou Montana (talk | contribs) m (Fix examples) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
__NOEDITSECTION__ | __NOEDITSECTION__ | ||
{{TOC|side}} | {{TOC|side}} | ||
[[SQF | [[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 ( | * 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> | ||
<sqs notrim> | |||
; This is a | ; This is a | ||
; multiline | ; multiline | ||
; comment | ; comment | ||
</sqs> | |||
<sqs>comment "this is a comment";</sqs> | |||
<sqs>"this is a comment";</sqs> | |||
| | | | ||
<sqf>// This is single-line comment</sqf> | |||
<sqf> | |||
/* | |||
This is a | |||
multiline | |||
comment | |||
*/ | |||
</sqf> | |||
<sqf>comment "this is a comment";</sqf> | |||
<sqf>"this is a comment";</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
Line 50: | Line 47: | ||
|- | |- | ||
| | | | ||
<sqs>@CONDITION</sqs> | |||
<sqs>@ not alive player</sqs> | |||
| | | | ||
<sqf>waitUntil { CONDITION };</sqf> | |||
<sqf>waitUntil { not alive player };</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
Line 62: | Line 57: | ||
|- | |- | ||
| | | | ||
<sqs>~DELAY</sqs> | |||
<sqs>~5</sqs> | |||
| | | | ||
<sqf>sleep DELAY;</sqf> | |||
<sqf>sleep 5;</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
Line 74: | Line 67: | ||
|- | |- | ||
| | | | ||
<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" | | ! colspan="2" | | ||
Line 86: | Line 77: | ||
|- | |- | ||
| | | | ||
<sqs notrim> | |||
? CONDITION : goto "SKIP" | |||
COMMAND_2 | |||
goto "END" | |||
#SKIP | |||
COMMAND_1 | |||
#END | #END | ||
</sqs> | |||
| | | | ||
<sqf> | |||
if (CONDITION) then | |||
{ | |||
COMMAND_1 | |||
} | |||
else | |||
{ | |||
COMMAND_2 | |||
}; | |||
</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
=== Cycle === | === Cycle === | ||
|- | |- | ||
| <sqs> | |||
#loop | |||
COMMAND | |||
~DELAY | |||
? CONDITION : goto "LOOP" | |||
</sqs> | |||
| | | | ||
<sqf> | |||
while { CONDITION } do { | |||
COMMAND; | |||
sleep DELAY; | |||
}; | |||
</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
=== Cycle with step === | === 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; | |||
}; | |||
</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
=== Structured conditional 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 | |||
| | </sqs> | ||
| <sqf> | |||
switch (VARIABLE) do | |||
{ | |||
case VALUE_1: | |||
{ COMMAND_1 }; | |||
case VALUE_2: | |||
{ COMMAND_2 }; | |||
default | |||
{ DEFAULT_COMMAND }; | |||
}; | |||
</sqf> | |||
|- | |- | ||
! colspan="2" | | ! colspan="2" | | ||
=== Exiting === | === Exiting === | ||
|- | |- | ||
| | | <sqs> | ||
? CONDITION : COMMAND_2 | |||
? CONDITION : exit | |||
COMMAND_1 | |||
| | </sqs> | ||
| <sqf notrim> | |||
if (CONDITION) exitWith { COMMAND_2; }; | |||
COMMAND_1; | |||
</sqf> | |||
|} | |} | ||
Line 172: | Line 179: | ||
== See Also == | == See Also == | ||
* [[SQF | * [[SQF Syntax]] | ||
* [[SQS Syntax]] | |||
* [[Introduction to Arma Scripting]] | |||
[[Category:Syntax]] | [[Category:Syntax]] |
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 |
|
Delay | |
~DELAY ~5 |
sleep DELAY; sleep 5; |
Conditional command | |
Multi-conditional command | |
Cycle | |
Cycle with step | |
Structured conditional command | |
Exiting | |