SQF Bytecode: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 25: Line 25:
<syntaxhighlight lang="cpp">
<syntaxhighlight lang="cpp">
{
{
    // list of folders that should be searched for .sqf scripts
    // search is performed recursively (sub-folders are searched as well)
     "inputDirs": [
     "inputDirs": [
       "P:/test/"
       "P:/test/"
     ],
     ],
    // list of paths that that contain the #include'd files into the scripts
    // this should be set the same as the P drive itself
    // if an external file is being #included by the .sqf script, such as #include "\a3\ui_f\hpp\definedikcodes.inc",
    // you need to create that file in the P drive, such as: P:\a3\ui_f\hpp\definedikcodes.inc
     "includePaths": [
     "includePaths": [
       "P:/"
       "P:/"
     ],
     ],
    // list of folders to be skipped
     "excludeList": [
     "excludeList": [
     ],
     ],
    // set this the same as P drive
     "outputDir": "P:/",
     "outputDir": "P:/",
    // how many threads will compile the scripts. each thread will compile one file at a time
     "workerThreads": 8
     "workerThreads": 8
}
}
</syntaxhighlight>
</syntaxhighlight>
</spoiler>
</spoiler>
# inputDirs: List of folders that should be searched for .sqf scripts. Search is performed recursively (sub-folders are searched as well)
# includePaths: list of paths that that contain the #include'd files into the scripts. This should be set the same as the P drive itself. If an external file is being [[PreProcessor_Commands#.23include|#include]]d by the .sqf script, such as {{ic|#include "\a3\ui_f\hpp\definedikcodes.inc"}}, you need to create that file in the P drive, such as: {{ic|P:\a3\ui_f\hpp\definedikcodes.inc}}
# outputDir: Set this the same as P drive if you want the .sqfc files to be created next to each .sqf file.
# excludeList: List of folders to be excluded from searching.
# workerThreads: How many threads will compile the scripts. Each thread will compile one file at a time
# Execute '''ArmaScriptCompiler.exe'''. It will compile the scripts and create an '''.sqfc''' file next to each '''.sqf''' file.
# Execute '''ArmaScriptCompiler.exe'''. It will compile the scripts and create an '''.sqfc''' file next to each '''.sqf''' file.
# In order to use the bytecode as compilation source in the game, use the [[compileScript]] command, or the [[Arma_3:_Functions_Library|Functions Library]].
# In order to use the bytecode as compilation source in the game, use the [[compileScript]] command, or the [[Arma_3:_Functions_Library|Functions Library]].

Revision as of 19:03, 26 January 2022

What is SQF bytecode?

An SQF bytecode is a file that contains the instructions to be executed in an SQF script. The bytecode is obtained after parsing the SQF script, which is written in a human-readable text-based file. Unlike an SQF script, an SQF bytecode is not human-readable.

As of Arma 3 V2.04, it is possible to use SQF bytecode files (with .sqfc format) as compilation sources of in-game scripts instead of normal .sqf scripts.

Bytecode Advantages

Using bytecode, as opposed to raw scripts, has the following benefits:

  1. Since the script is already parsed, parsing is skipped during compilation, which reduces compilation time.
  2. Certain optimizations - that would take a long time to detect by the in-game compiler - can be detected and included in the bytecode, which improves execution performance.

Bytecode Disadvantages

A bytecode is not human-readable and thus cannot be easily modified.

How to use SQF Bytecode

In order to use bytecode, an SQF script compiler is needed. See Dedmen's Arma Script Compiler for an example of an SQF compiler.


To compile a SQF Bytecode using Arma Script Compiler:

  1. Mount the P drive
  2. Copy the script files into a folder on the P drive. They can be organized into sub-folders if needed.
  3. Download Arma Script Compiler and extract the files into a folder.
  4. Create a sqfc.json file in the same folder as where the script compiler's executable file is located.
  5. Edit the sqfc.json file according to the following template:

{
    "inputDirs": [
      "P:/test/"
    ],
    "includePaths": [
      "P:/"
    ],
    "excludeList": [
    ],
    "outputDir": "P:/",
    "workerThreads": 8
}

  1. inputDirs: List of folders that should be searched for .sqf scripts. Search is performed recursively (sub-folders are searched as well)
  2. includePaths: list of paths that that contain the #include'd files into the scripts. This should be set the same as the P drive itself. If an external file is being #included by the .sqf script, such as #include "\a3\ui_f\hpp\definedikcodes.inc", you need to create that file in the P drive, such as: P:\a3\ui_f\hpp\definedikcodes.inc
  3. outputDir: Set this the same as P drive if you want the .sqfc files to be created next to each .sqf file.
  4. excludeList: List of folders to be excluded from searching.
  5. workerThreads: How many threads will compile the scripts. Each thread will compile one file at a time
  1. Execute ArmaScriptCompiler.exe. It will compile the scripts and create an .sqfc file next to each .sqf file.
  2. In order to use the bytecode as compilation source in the game, use the compileScript command, or the Functions Library.