SQF Syntax

Jawshy edited this page Sep 25, 2016 · 1 revision

How to understand SQF Syntax:

SQF is a pseudocode based in C syntax, but without many advanced functions as pointers or memory allocators. Also, SQF has many functions related to the RV Engine that makes the life easier. It's used in MODs and also in the main game files, in both cases the code is executed through an API wrote in C# (NET).

If you know how to code in C, C++, C# or even java, you'll know how to code in SQF, and this is why you should start with the basic from one of these languages.

The next step, is learning the SQF functions. Here are some of them:

Function: Info: Example:
player the player that is executing the script. if((vehicle player) == player) then {};
exitWith exits the current scope. if(_var == 1) exitWith {};
waitUntil waits 'till something is done. (Only for spawned scripts). waitUntil{_var == 1};
forEach selects each value from an array and executes a code with it set as _x. { _var = _x }forEach [1,2,3,4];
isNull checks if something returns as objNull. if(isNull _var) then {};
remoteExec spawns a function in MP for each player set. [] remoteExec ["function",player]
remoteExecCall calls a function in MP for each player set. [] remoteExecCall ["function",player]
playerSide returns the player side if(playerSide == west) then {};

You can find all the functions in Bohemia's wiki.

Spawn vs Call
The main diference is that, when calling something, all the script after that will wait 'till it's done. Also, only spawned scripts can take use of suspension functions as "sleep" and "waitUntil". (execVM can too, but it isn't the case here.)

Since you know how to code, remember always to keep the file style (spacing, etc.) for a better reading.
Also, never forget the semicolon.