{"name":"SQF Bytecode","title":"SQF Bytecode","type":"topic","url":"https://community.bistudio.com/wiki/SQF_Bytecode","revid":370227,"updated":"2024-11-12T18:44:27Z","aliases":[],"markdown":"An SQF [bytecode](https://en.wikipedia.org/wiki/Bytecode) is a file that contains the instructions to be executed in an SQF script.\nThe bytecode is obtained after parsing the SQF script, which is written in a human-readable text-based file. Unlike an SQF script, SQF bytecode is not human-readable.\n\nAs of Arma 3 v2.04, it is possible to use SQF bytecode files (with the `.sqfc` extension) as compilation sources of in-game scripts instead of normal .sqf scripts, using the compileScript command.\nThe Functions Library has also been modified to use this command.\n\n**Using bytecode as opposed to raw scripts**\n\n| Pros | Cons |\n|---|---|\n| - Since the script is already parsed, parsing is skipped during compilation, which reduces compilation time. This improvement can be quite significant if the script uses PreProcessor Commands.<br>- Certain optimisations - 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. | - A bytecode is not human-readable and thus cannot be easily modified. |\n\n### How to use SQF Bytecode\n\nIn order to use bytecode, a SQF script compiler is needed. See [Dedmen's Arma Script Compiler](https://github.com/dedmen/ArmaScriptCompiler) for an example of an SQF compiler.\n\nTo compile an SQF script into SQF Bytecode using Arma Script Compiler:\n\n1. Mount the P drive (called \"Mount the Project Drive\" in Arma 3 Tools)\n1. Copy the script files into a folder on the P drive. They can be organized into sub-folders if needed.\n1. Download [Arma Script Compiler](https://github.com/dedmen/ArmaScriptCompiler/releases) and extract the files into a folder.\n1. Create a **sqfc.json** file next to the script compiler's executable file (**ArmaScriptCompiler.exe**).\n1. Edit the **sqfc.json** file according to the following template:\n\n   ```json\n   {\n       \"inputDirs\": [\n           \"P:/folder1/\",\n           \"P:/folder2/\"\n       ],\n       \"includePaths\": [\n           \"P:/\"\n       ],\n       \"excludeList\": [\n           \"subfolder1\",\n           \"subfolder2\",\n           \"subfolder3/subfolder4\"\n       ],\n       \"outputDir\": \"P:/\",\n       \"workerThreads\": 8\n   }\n   ```\n   - inputDirs: List of folders that should be searched for .sqf scripts. Search is performed recursively (sub-folders are searched as well)\n   - includePaths: list of paths that contain the #included files into the scripts. This should be set the same as the P drive path `P:\\` to work correctly. 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 on the P drive, such as: `P:\\a3\\ui_f\\hpp\\definedikcodes.inc`\n   - outputDir: Set this the same as P drive if you want the .sqfc files to be created next to each .sqf file.\n   - excludeList: List of folders to be excluded from searching.\n   - workerThreads: How many threads will compile the scripts. Each thread will compile one file at a time\n1. Execute **ArmaScriptCompiler.exe**. It will compile the scripts and create an **.sqfc** file next to each **.sqf** file.\n1. In order to use the bytecode as compilation source in the game, use the compileScript command, or the Functions Library.","sections":[{"heading":null,"level":1,"markdown":"An SQF [bytecode](https://en.wikipedia.org/wiki/Bytecode) is a file that contains the instructions to be executed in an SQF script.\nThe bytecode is obtained after parsing the SQF script, which is written in a human-readable text-based file. Unlike an SQF script, SQF bytecode is not human-readable.\n\nAs of Arma 3 v2.04, it is possible to use SQF bytecode files (with the `.sqfc` extension) as compilation sources of in-game scripts instead of normal .sqf scripts, using the compileScript command.\nThe Functions Library has also been modified to use this command.\n\n**Using bytecode as opposed to raw scripts**\n\n| Pros | Cons |\n|---|---|\n| - Since the script is already parsed, parsing is skipped during compilation, which reduces compilation time. This improvement can be quite significant if the script uses PreProcessor Commands.<br>- Certain optimisations - 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. | - A bytecode is not human-readable and thus cannot be easily modified. |"},{"heading":"How to use SQF Bytecode","level":3,"markdown":"In order to use bytecode, a SQF script compiler is needed. See [Dedmen's Arma Script Compiler](https://github.com/dedmen/ArmaScriptCompiler) for an example of an SQF compiler.\n\nTo compile an SQF script into SQF Bytecode using Arma Script Compiler:\n\n1. Mount the P drive (called \"Mount the Project Drive\" in Arma 3 Tools)\n1. Copy the script files into a folder on the P drive. They can be organized into sub-folders if needed.\n1. Download [Arma Script Compiler](https://github.com/dedmen/ArmaScriptCompiler/releases) and extract the files into a folder.\n1. Create a **sqfc.json** file next to the script compiler's executable file (**ArmaScriptCompiler.exe**).\n1. Edit the **sqfc.json** file according to the following template:\n\n   ```json\n   {\n       \"inputDirs\": [\n           \"P:/folder1/\",\n           \"P:/folder2/\"\n       ],\n       \"includePaths\": [\n           \"P:/\"\n       ],\n       \"excludeList\": [\n           \"subfolder1\",\n           \"subfolder2\",\n           \"subfolder3/subfolder4\"\n       ],\n       \"outputDir\": \"P:/\",\n       \"workerThreads\": 8\n   }\n   ```\n   - inputDirs: List of folders that should be searched for .sqf scripts. Search is performed recursively (sub-folders are searched as well)\n   - includePaths: list of paths that contain the #included files into the scripts. This should be set the same as the P drive path `P:\\` to work correctly. 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 on the P drive, such as: `P:\\a3\\ui_f\\hpp\\definedikcodes.inc`\n   - outputDir: Set this the same as P drive if you want the .sqfc files to be created next to each .sqf file.\n   - excludeList: List of folders to be excluded from searching.\n   - workerThreads: How many threads will compile the scripts. Each thread will compile one file at a time\n1. Execute **ArmaScriptCompiler.exe**. It will compile the scripts and create an **.sqfc** file next to each **.sqf** file.\n1. In order to use the bytecode as compilation source in the game, use the compileScript command, or the Functions Library."}],"categories":["Arma 3: Editing"],"groups":["Scripting"]}