call: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Fix wrong call STRING example)
(cleaned up, formatted)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Executes the function string.
| Executes given set of compiled instructions with an option to pass arguments to the executed [[Code]]. In [[OFP]] this command used to accept [[String]] for the code. |= Description
____________________________________________________________________________________________


The ''argument(s)'' (if any) are passed as _this. (''argument(s)'' are passed in an array).
| '''call''' code |= Syntax


To execute a [[sleep]] function in the called code, execute it with [[spawn]] instead. |= Description
|p1= code: [[Code]] - [[compile]]d instructions
____________________________________________________________________________________________


| argument(s) '''call''' body |= Syntax
| [[Anything]] - The last value given in the function is returned. See the topic [[Function#Return_Values|Function]] for more information. |= Return value


|p1= argument(s): [[Any Value]] - Optional. Argument that is passed to the function in the "_this" variable. |= Parameter 1
| s2= args '''call''' code |= Syntax


|p2= body: [[Code]] - A function body provided directly 'inline' or
|p21= args: [[Anything]] - Arguments that are passed to the function in the "_this" variable. |= Parameter 1
the [[String]] returned from the commands [[loadFile]] or [[preprocessFile]].


|p22= code: [[Code]] - [[compile]]d instructions


| [[Anything]] -
|r2= [[Anything]] - The last value given in the function is returned. See the topic [[Function#Return_Values|Function]] for more information. |= Return value
The last value given in the function is returned. See the topic [[Function#Return_Values|Function]] for more information. |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________


|x1= <code>call "x <nowiki>=</nowiki> 3"</code> |= Example 1
|x1= <code>[[call]] {[[hint]] [[str]] 123};</code> |= Example 1
 
|x2= <code>123 [[call]] {[[hint]] [[str]] _this};</code>|= Example 2
 
|x3= <code>_sum = [1, 2] [[call]] {(_this [[select]] 0) + (_this [[select]] 1)};
[[hint]] [[str]] _sum; //3</code> |= Example 3


|x2= ''[[:Category:Operation Flashpoint|Operation Flashpoint]] syntax:''
|x4= <code>123 [[call]] [[compile]] "[[hint]] [[str]] _this";</code>|= Example 4
<code>_n <nowiki>=</nowiki> 3;<br />call [[format]] [{var%1 <nowiki>=</nowiki> 0},_n];</code>
''[[:Category:Armed Assault|Armed Assault]] syntax:''
<code>_n <nowiki>=</nowiki> 3;<br />call [[compile]] [[format]] ["var%1 <nowiki>=</nowiki> 0",_n];</code>
result of both syntaxes is '''var3 <nowiki>=</nowiki> 0'''|= Example 2


|x3= ''[[:Category:Operation Flashpoint|Operation Flashpoint]] syntax:''
|x5= <code>_result = 123 [[call]] [[compile]] [[preprocessFileLineNumbers]] "myfile.sqf";</code>|= Example 5
<code>_fAdd <nowiki>=</nowiki> loadFile "add.sqf"
[1,2] call _fAdd</code>
''[[:Category:Armed Assault|Armed Assault]] syntax:''
<code>_fAdd <nowiki>=</nowiki> [[compile]] loadFile "add.sqf"
_result <nowiki>=</nowiki> [1,2] call _fAdd</code>  
|= Example 3
____________________________________________________________________________________________
____________________________________________________________________________________________



Revision as of 13:26, 13 February 2017

Hover & click on the images for description

Description

Description:
Executes given set of compiled instructions with an option to pass arguments to the executed Code. In OFP this command used to accept String for the code.
Groups:
Uncategorised

Syntax

Syntax:
call code
Parameters:
code: Code - compiled instructions
Return Value:
Anything - The last value given in the function is returned. See the topic Function for more information.

Alternative Syntax

Syntax:
args call code
Parameters:
args: Anything - Arguments that are passed to the function in the "_this" variable.
code: Code - compiled instructions
Return Value:
Anything - The last value given in the function is returned. See the topic Function for more information.

Examples

Example 1:
call {hint str 123};
Example 2:
123 call {hint str _this};
Example 3:
_sum = [1, 2] call {(_this select 0) + (_this select 1)}; hint str _sum; //3
Example 4:
123 call compile "hint str _this";
Example 5:
_result = 123 call compile preprocessFileLineNumbers "myfile.sqf";

Additional Information

See also:
spawnexecVMcanSuspendcompilepreprocessFile

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

Notes

Bottom Section

Posted on July 5, 2014 - 16:00 (UTC)
MattAka Horner

A called function may only use suspension (sleep, uiSleep, waitUntil) if it originates in a scheduled environment. If the called function originates in a non-scheduled environment it will return a generic error.
// *** non-scheduled origin *** [] spawn { // *** scheduled scope *** [] call { // *** scheduled scope *** sleep 3; // <- OK hintSilent "Hello World!"; }; }; // *** non-scheduled origin *** [] call { // *** non-scheduled scope*** [] call { // *** non-scheduled scope *** sleep 3; // <- NOT OK hintSilent "Hello World!"; }; }; // *** scheduled origin *** [] spawn { // *** scheduled scope *** [] call { // *** scheduled scope *** sleep 3; // <- OK hintSilent "Hello World!"; }; }; // *** scheduled origin *** [] call { // *** scheduled scope*** [] call { // *** scheduled scope *** sleep 3; // <- OK hintSilent "Hello World!"; }; };
Posted on February 17, 2015 - 11:02 (UTC)
Patriot821
If the code is in non-scheduled scope and contains while-do statement, the code runs only 10000 times at the maximum, even if the statement makes infinite loop. (ARMA3 Ver. 1.38.128937) // *** non-scheduled origin *** [] call { // *** non-scheduled scope*** [] call { // *** non-scheduled scope *** _a=0; while{_a<15000} do{ _a=_a+1; }; hint str(_a);//10000 }; };