{"name":"execVM","title":"execVM","type":"command","url":"https://community.bistudio.com/wiki/execVM","revid":336954,"updated":"2023-01-04T16:44:15Z","groups":["Program Flow"],"status":"ok","games":{"arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma1 1.00","arma3_since":"0.50","locality":{"argument":"global","effect":"local"},"description":"Compiles and adds an SQF script to the scheduler queue and returns script handle (see also Example 4).\nThe script does not execute immediately upon running execVM command but with some delay depending on the VM's scripts queue and engine load.\n\n> [!NOTE]\n> - If the same script is to be executed more than one time, declaring it as a Function is recommended to avoid recompiling and wasting performance with every execution.\n> - The script is searched for in the following directories in that order:\n>   - mission directory\n>   - campaign scripts directory\n>   - global scripts directory.\n> - To see what VM scripts are currently in the scheduler, use diag_activeSQFScripts command.\n\n> [!IMPORTANT]\n> - The `.sqf` file extension is not mandatory but is strongly recommended as using non-standard extensions may cause problems during binarisation\n> - If the script file is not prepared using UTF-8 encoding and contains some characters with codes > 127, they might convert incorrectly.","syntaxes":[{"syntax":"arguments execVM filename","params":[{"name":"arguments","type":"Anything","description":"arguments accessible as `_this` in the script","type_expr":"Anything"},{"name":"filename","type":"String","description":"path to the SQF script file","type_expr":"String"}],"returns":{"type":"Script Handle","type_expr":"Script Handle"},"form":"binary","left":{"text":"arguments"},"right":{"text":"filename"}},{"syntax":"execVM filename","params":[{"name":"filename","type":"String","description":"path to the SQF script file","type_expr":"String"}],"returns":{"type":"Script Handle","type_expr":"Script Handle"},"form":"unary","right":{"text":"filename"}}],"examples":[{"code":["execVM \"test.sqf\";"]},{"text":"```sqf\n_handle = player execVM \"test.sqf\";\nwaitUntil { scriptDone _handle };\n```\n\nThe following is also possible in Arma 3:\n\n```sqf\nprivate _handle = execVM \"123.sqf\";\nwaitUntil { isNull _handle };\n```","code":["_handle = player execVM \"test.sqf\";\nwaitUntil { scriptDone _handle };","private _handle = execVM \"123.sqf\";\nwaitUntil { isNull _handle };"]},{"text":"```sqf\n[player, 0.75] execVM \"setDamage.sqf\";\n```\n\nsetDamage.sqf:\n\n```sqf\nparams [\"_unit\", \"_damage\"];\n_unit setDamage _damage;\n```","code":["[player, 0.75] execVM \"setDamage.sqf\";","params [\"_unit\", \"_damage\"];\n_unit setDamage _damage;"]},{"text":"execVM equivalence:\n\n```sqf\nprivate _handle = _args execVM \"someFile.sqf\";\n// is practically identical to\nprivate _handle = _args spawn compile preprocessFileLineNumbers \"someFile.sqf\";\n```","code":["private _handle = _args execVM \"someFile.sqf\";\n// is practically identical to\nprivate _handle = _args spawn compile preprocessFileLineNumbers \"someFile.sqf\";"]}],"see_also":["call","spawn","exec","execFSM","scriptDone","scriptNull","terminate","sleep","uiSleep","waitUntil","canSuspend","diag_activeScripts","diag_activeSQFScripts","SQF Syntax","Control Structures"]}