call: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{arma}}" to "{{arma1}}")
(Add un/scheduled informative note)
Line 11: Line 11:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Adds given set of compiled instructions to the current stack and waits for it to finish and return, provides an option to pass arguments to the executed [[Code]].<br><br>
| Adds given set of compiled instructions to the current stack and waits for it to finish and return, provides an option to pass arguments to the executed [[Code]].
{{Important|In [[:Category:{{ofp}}|{{ofp}}]] this command used to accept [[String]] as well as [[Code]]. This does not apply to {{arma1}} and later titles (see [[compile]]).}}|Description=
{{Informative | [[call]]ed code runs in the scope it is called, as if the code were copy-pasted there, [[Scheduler|(un)scheduled environment]] included.}}  
{{Important | This command accepts [[String]] (as well as [[Code]]) only in {{GameCategory|ofp|link=y}}. For later titles, see [[compile]].}}|Description=
____________________________________________________________________________________________
____________________________________________________________________________________________


Line 35: Line 36:


|x3= <code>_sum = [1, 2] [[call]] { ([[_this]] [[select]] 0) + ([[_this]] [[select]] 1); };
|x3= <code>_sum = [1, 2] [[call]] { ([[_this]] [[select]] 0) + ([[_this]] [[select]] 1); };
[[hint]] [[str]] _sum; {{codecomment|// displays 3}}</code> |Example 3=
[[hint]] [[str]] _sum; {{cc|displays 3}}</code> |Example 3=


|x4= <code>123 [[call]] [[compile]] "[[hint]] [[str]] _this;";</code> |Example 4=
|x4= <code>123 [[call]] [[compile]] "[[hint]] [[str]] _this;";</code> |Example 4=
Line 54: Line 55:
<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.96|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands OFP 1.99|{{uc:{{PAGENAME}}}}]]
Line 61: Line 61:
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on July 5, 2014 - 16:00 (UTC)</dd>
<dt class="note">[[User:MattAka Horner|MattAka Horner]]</dt>
<dd class="note">A called function may only use suspension ([[sleep]], [[uiSleep]], [[waitUntil]]) if it originates in a [[Scheduler#Scheduled_Environment|scheduled environment]]. If the called function originates in a [[Scheduler#Unscheduled_Environment|non-scheduled environment]] it will return a generic error:
<code>{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] origin ***}}
[] [[spawn]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[[sleep]] 3; {{codecomment|// <- OK}}
[[hintSilent]] "Hello World!";
};
};</code>
<code>{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] origin ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] scope***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] scope ***}}
[[sleep]] 3; {{codecomment|// <- NOT OK}}
[[hintSilent]] "Hello World!";
};
};</code>
<code>{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] origin ***}}
[] [[spawn]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[[sleep]] 3; {{codecomment|// <- OK}}
[[hintSilent]] "Hello World!";
};
};</code>
<code>{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] origin ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Scheduled_Environment|scheduled]] scope ***}}
[[sleep]] 3; {{codecomment|// <- OK}}
[[hintSilent]] "Hello World!";
};
};</code>
</dd>
<dd class="notedate">Posted on February 17, 2015 - 11:02 (UTC)</dd>
<dt class="note">[[User:Patriot821|Patriot821]]</dt>
<dd class="note">If the code is in [[Scheduler#Unscheduled_Environment|non-scheduled]] scope and contains while-do statement, the code runs only 10,000 times at the maximum, even if the statement makes infinite loop. (ARMA3 Ver. 1.38.128937)
<code>{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] origin ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] scope ***}}
[] [[call]] {
{{codecomment|// *** [[Scheduler#Unscheduled_Environment|non-scheduled]] scope ***}}
_a = 0;
[[while]] { _a < 15000 } [[do]] {
_a = _a + 1;
};
[[hint]] [[str]] _a; {{codecomment|// displays 10000}}
};
};</code>
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Revision as of 21:26, 1 January 2021

Hover & click on the images for description

Description

Description:
Adds given set of compiled instructions to the current stack and waits for it to finish and return, provides an option to pass arguments to the executed Code.
called code runs in the scope it is called, as if the code were copy-pasted there, (un)scheduled environment included.
This command accepts String (as well as Code) only in Operation Flashpoint. For later titles, see compile.
Groups:
Program Flow

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; // displays 3
Example 4:
123 call compile "hint str _this;";
Example 5:
_result = 123 call compile preprocessFileLineNumbers "myFile.sqf";

Additional Information

See also:
spawnexecVMcanSuspendcompilepreprocessFileremoteExecremoteExecCall

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