# execVM ## Category Code Execution ## Arity **Unary** — `execVM `. ``` execVM // path to .sqf file ``` ## Description Reads an `.sqf` file from disk, compiles it, and spawns it asynchronously on the current scheduler. Returns a `ScriptHandle`. This is the primary way to load and execute external script files. ## How It Works 1. Reads the file content from the given path. 2. Compiles the source text into a `Code` value using the SQ# compiler. 3. Spawns the compiled code as a new fiber on the current scheduler. 4. Returns a `ScriptHandle`. Equivalent to `spawn compile (readFile _path)` but as a single efficient operation. ## Usage ### Basic file execution ```sqf _handle = execVM "scripts\init.sqf"; ``` ### With await ```sqf _handle = execVM "scripts\setup.sqf"; await _handle; systemChat "Setup complete"; ``` ### Loading multiple scripts ```sqf { _handles pushBack (execVM _x); } forEach [ "scripts\ai.sqf", "scripts\spawns.sqf", "scripts\loot.sqf" ]; ``` ### Check if file exists before exec ```sqf if (!isNil { execVM "optional\addon.sqf" }) then { // file exists and was spawned }; ``` ## Thread Safety Creates fiber on the current scheduler. File reading is synchronous (blocks briefly). The spawned code runs on the current scheduler. ## See Also - [spawn](spawn.md) — spawn inline code - [compile](compile.md) — compile string to code - [call](call.md) — synchronous execution - [await](await.md) — wait for handle