{"name":"execVM","operator":null,"title":"execVM","type":"command","url":"https://community.bistudio.com/wiki/execVM","revid":336954,"updated":"2023-01-04T16:44:15Z","groups":["Program Flow"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.00"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":"global","effect":"local","server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"arguments","type":"Anything","optional":false,"default":null,"description":"arguments accessible as `_this` in the script","types":["Anything"],"since":null,"text":"arguments: Anything - arguments accessible as `_this` in the script"},{"name":"filename","type":"String","optional":false,"default":null,"description":"path to the SQF script file","types":["String"],"since":null,"text":"filename: String - path to the SQF script file"}],"returns":{"type":"Script Handle","types":["Script Handle"],"description":null,"text":"Script Handle"},"form":"binary","operator":null,"left":{"text":"arguments","types":["Anything"]},"right":{"text":"filename","types":["String"]}},{"syntax":"execVM filename","since":null,"effect":null,"exec":null,"params":[{"name":"filename","type":"String","optional":false,"default":null,"description":"path to the SQF script file","types":["String"],"since":null,"text":"filename: String - path to the SQF script file"}],"returns":{"type":"Script Handle","types":["Script Handle"],"description":null,"text":"Script Handle"},"form":"unary","operator":null,"left":null,"right":{"text":"filename","types":["String"]}}],"examples":[{"text":"```sqf\nexecVM \"test.sqf\";\n```","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\";"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["call","spawn","exec","execFSM","scriptDone","scriptNull","terminate","sleep","uiSleep","waitUntil","canSuspend","diag_activeScripts","diag_activeSQFScripts","SQF Syntax","Control Structures"],"notes":[],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Program Flow","Introduced with Armed Assault version 1.00","Scripting Commands","Scripting Commands: Local Effect","Take On Helicopters: Scripting Commands"]}