execVM: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Text replacement - "{{HashLink" to "{{Link")
 
(101 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= arma1
|version1= 1.00


|1.00|= Game version
|game2= arma2
____________________________________________________________________________________________
|version2= 1.00


| Compile and execute [[SQF_syntax|SQF]] [[Script]].
|game3= arma2oa
|version3= 1.50


The '''optional''' argument is passed to the script as local variable _this.
|game4= tkoh
|version4= 1.00


Script is compiled every time you use this command.
|game5= arma3
|version5= 0.50


The [[Script]] is first searched for in the mission folder, then in the campaign scripts folder and finally in the global scripts folder. |= Description
|arg= global
____________________________________________________________________________________________
|eff= local


| [[Script]] <nowiki>=</nowiki> argument '''execVM''' filename |= Syntax
|gr1= Program Flow


|p1= argument: [[Any Value]](s) |= Parameter 1
|descr= Compiles and adds an [[SQF Syntax|SQF]] [[Script Handle|script]] to the [[Scheduler|scheduler]] queue and returns script handle (see also {{Link|#Example 4}}).
The script does not execute immediately upon running [[execVM]] command but with some delay depending on the VM's scripts queue and engine load.


|p2= filename: [[String]] |= Parameter 2
{{Feature|informative|
 
* If the same script is to be executed more than one time, declaring it as a [[Arma 3: Functions Library|Function]] is recommended to avoid recompiling and wasting performance with every execution.
| [[Script]] - script handle, which can be used to determine (via [[scriptDone]]) when the called script has finished.|= Return value
* The script is searched for in the following directories in that order:
____________________________________________________________________________________________
** mission directory
 
** campaign scripts directory
|x1= <code>_handle <nowiki>=</nowiki> [[player]] execVM "test.sqf";
** global scripts directory.
waitUntil {scriptDone _Handle};</code> |= Example 1
* To see what VM scripts are currently in the scheduler, use [[diag_activeSQFScripts]] command.
____________________________________________________________________________________________
}}
 
| [[exec]], [[execFSM]], [[scriptDone]], [[terminate]], [[SQF syntax]], [[Control Structures]] |= See also


{{Feature|important|
* The {{hl|.sqf}} file extension is not mandatory but is strongly recommended as using non-standard extensions may cause problems during binarisation
* If the script file is not prepared using UTF-8 encoding and contains some characters [[toArray|with codes]] > 127, they might convert incorrectly.
}}
}}


<h3 style="display:none">Notes</h3>
|s1= arguments [[execVM]] filename
<dl class="command_description">
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on January 5, 2007 - 12:30</dd>
<dt class="note">'''[[User:Giova|Giova]]'''</dt><dd class="note">More about the Returned value:''


the type 'Script' returned by this command, is in fact a kind of 'Thread Handle'.
|p1= arguments: [[Anything]] - arguments accessible as {{hl|[[Magic Variables#this|_this]]}} in the script


|p2= filename: [[String]] - path to the [[SQF Syntax|SQF]] script file


GOOD POINT:
|r1= [[Script Handle]]


sqf functions launched with execVM will run asynchronously from its caller script/function.
|s2= [[execVM]] filename


It is possible to manage multi-threading development, by using:
|p21= filename: [[String]] - path to the [[SQF Syntax|SQF]] script file


-handle script returned by execVM
|r2= [[Script Handle]]


-force the thread to terminate by using 'terminate' command
|x1= <sqf>execVM "test.sqf";</sqf>


-synchronise a script by using 'ScriptDone' command
|x2= <sqf>
_handle = player execVM "test.sqf";
waitUntil { scriptDone _handle };
</sqf>
The following is also possible in {{arma3}}:
<sqf>
private _handle = execVM "123.sqf";
waitUntil { isNull _handle };
</sqf>


|x3= <sqf>[player, 0.75] execVM "setDamage.sqf";</sqf>
setDamage.sqf:
<sqf>
params ["_unit", "_damage"];
_unit setDamage _damage;
</sqf>


BAD POINT:
|x4= [[execVM]] equivalence:
<sqf>
private _handle = _args execVM "someFile.sqf";
// is practically identical to
private _handle = _args spawn compile preprocessFileLineNumbers "someFile.sqf";
</sqf>


-sqf funcion cannot return value (because execVM is already returning the thread Handle)
|seealso= [[call]] [[spawn]] [[exec]] [[execFSM]] [[scriptDone]] [[scriptNull]] [[terminate]] [[sleep]] [[uiSleep]] [[waitUntil]] [[canSuspend]] [[diag_activeScripts]] [[diag_activeSQFScripts]] [[SQF Syntax]] [[Control Structures]]
 
}}
-the variable _time does not work in sqf called with execVM command
</dd>
 
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Notes</h3>
<dl class="command_description">
<!-- Note Section BEGIN -->
 
<dd class="notedate">Posted on November 23, 2010 - 15:56</dd>
<dt class="note">'''[[User:Kabilen|Kabilen]]'''</dt><dd class="note">Passing variables to the script file''
 
To pass multiple variables to the script file, use an array e.g:
 
'''null = [myunit,1234] execVM "test.sqf";'''
 
Now within test.sqf to access the elements, use the following:
 
'''_myunit = _this select 0;'''<br>
'''_myvar = _this select 1;'''
 
</dd>
 
 
<!-- Note Section END -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
 
[[Category:Scripting Commands|EXECVM]]
[[Category:Scripting Commands ArmA|EXECVM]]
[[Category:Command Group: Program Flow|EXECVM]]
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands VBS2|{{uc:{{PAGENAME}}}}]]

Latest revision as of 17:44, 4 January 2023

Hover & click on the images for description

Description

Description:
Compiles and adds an SQF script to the scheduler queue and returns script handle (see also Example 4). The script does not execute immediately upon running execVM command but with some delay depending on the VM's scripts queue and engine load.
  • 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.
  • The script is searched for in the following directories in that order:
    • mission directory
    • campaign scripts directory
    • global scripts directory.
  • To see what VM scripts are currently in the scheduler, use diag_activeSQFScripts command.
  • The .sqf file extension is not mandatory but is strongly recommended as using non-standard extensions may cause problems during binarisation
  • If the script file is not prepared using UTF-8 encoding and contains some characters with codes > 127, they might convert incorrectly.
Groups:
Program Flow

Syntax

Syntax:
arguments execVM filename
Parameters:
arguments: Anything - arguments accessible as _this in the script
filename: String - path to the SQF script file
Return Value:
Script Handle

Alternative Syntax

Syntax:
execVM filename
Parameters:
filename: String - path to the SQF script file
Return Value:
Script Handle

Examples

Example 1:
execVM "test.sqf";
Example 2:
_handle = player execVM "test.sqf"; waitUntil { scriptDone _handle };
The following is also possible in Arma 3:
private _handle = execVM "123.sqf"; waitUntil { isNull _handle };
Example 3:
[player, 0.75] execVM "setDamage.sqf";
setDamage.sqf:
params ["_unit", "_damage"]; _unit setDamage _damage;
Example 4:
execVM equivalence:
private _handle = _args execVM "someFile.sqf"; // is practically identical to private _handle = _args spawn compile preprocessFileLineNumbers "someFile.sqf";

Additional Information

See also:
call spawn exec execFSM scriptDone scriptNull terminate sleep uiSleep waitUntil canSuspend diag_activeScripts diag_activeSQFScripts SQF Syntax Control Structures

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note