Difference between revisions of "Arma 3: Functions Library"

From Bohemia Interactive Community
Jump to navigation Jump to search
m
Line 3: Line 3:
 
Arma 3 '''Functions Library''' is pack of routine script functions available from anywhere in game. Main difference from older [[Functions Library]] is that it runs automatically and doesn't require Functions manager to be present.
 
Arma 3 '''Functions Library''' is pack of routine script functions available from anywhere in game. Main difference from older [[Functions Library]] is that it runs automatically and doesn't require Functions manager to be present.
  
 +
== Finding a Function ==
 +
[[File:A3_functionwViewer.png|300px|thumb|right|Functions Viewer]]
 +
Before you can use a function, you first need to find it. The easies way is to access the '''Functions Viewer''':
  
 +
* In editor, click on [[File:icon editor functions.png|20px]] icon or press Ctrl + F
 +
* In mission, access the [[Mission_Editor:_Debug_Console|debug console]] (automatically visible in pause menu of an editor mission) and click on '''FUNCTIONS''' button.
 +
 +
Once in the '''Functions Viewer''', you can filter all available functions by location, projects and categories.
 +
 +
When you find the desired function, look at the code preview on the right. Every function has a header where you can find basic description of its functionality including required arguments, returned values and sometimes examples of use.
 +
 +
{{note|Some functions, especially the older ones, may have missing or incomplete headers.<br />We do our best to update them, but if you find some issues, feel free to report them in the [http://feedback.arma3.com/ Feedback Tracker].}}
 +
 +
 +
== Calling a Function ==
 +
Functions can be launched in mission, intro and outro using this [[call]] or [[spawn]] commands:
 +
_returnedValue = ''arguments'' [[call]] ''functionName'';
 +
''arguments'' [[spawn]] ''functionName'';
 +
 +
=== Arguments ===
 +
Arguments are data sent into the function, affecting its behavior.
 +
 +
They can be '''mandatory''' or '''optional'''.
 +
* Mandatory arguments are required for function to run. When missing, the function usually stops and throws an error.
 +
* Optional arguments allows more detailed configuration. If you dont send them, the function will use pre-defined default values.
 +
 +
{{note|Within the function, '''arguments''' are called '''parameters''', or simply params.}}
 +
 +
 +
For example, let's take a look at [[BIS_fnc_endMission]], a function which ends a mission with animated closing shot. This is what the header says:
 +
/*
 +
Author: Karel Moricky
 +
 +
Description:
 +
Ends mission with specific ending.
 +
 +
<span style="color:DarkCyan;">Parameter(s):
 +
0 (Optional):
 +
STRING - end name (default: "end1")
 +
ARRAY in format [endName,ID], will be composed to "endName_ID" string
 +
1 (Optional): BOOL - true to end mission, false to fail mission (default: true)
 +
2 (Optional):
 +
BOOL - true for signature closing shot (default: true)
 +
NUMBER - duration of a simple fade out to black</span>
 +
 +
Returns:
 +
BOOL
 +
*/
 +
 +
As you can see, all arguments are marked optional and you can call the function without them.
 +
 +
[] call BIS_fnc_endMission;
 +
:This will result in successfull ending of type "end1", preceeded with the signature [[Debriefing|closing shot]].
 +
 +
["end2"] call BIS_fnc_endMission;
 +
:Set the ending type to "end2", while keeping the other arguments intact.
 +
 +
["end2",false,false] call BIS_fnc_endMission;
 +
:Fail the mission without any effect, using "end2" type.
 +
 +
 +
However, what should you do if you want to set the '''only''' last argument without affecting the previous ones? The solution is simple - put an empty variable [[nil]] on their place.
 +
 +
<nowiki>[</nowiki>[[nil]],[[nil]],false] call BIS_fnc_endMission;
 +
:Disable the closing effects, but keep the other aguments intact (successful "end1").
 +
 +
{{note|Some older functions are incompatible with this syntax and using nil would break them. See their header for more information.}}
 +
 +
=== Returned Value ===
 +
Functions executed by [[call]] command can return back a value. Let's take a look at [[BIS_fnc_sideName]]:
 +
 +
/*
 +
Author: Karel Moricky
 +
 +
Description:
 +
Returns side name
 +
 +
Parameter(s):
 +
0: SIDE or NUMBER - either side or side ID
 +
 +
<span style="color:DarkCyan;">Returns:
 +
STRING</span>
 +
*/
 +
The function returns a [[String]] - localized name of a side.
 +
_westName = [[west]] call BIS_fnc_sideName;
 +
:Variable _westName will now be "BLUFOR" (or other name, based on selected language)
 +
 +
=== Multiplayer ===
 +
Functions executed using [[call]] or [[spawn]] command will run only on the computer which triggered them. If you'd wish to execute a function remotely on specific clients, use [[BIS_fnc_MP]] function.
 +
[arguments,''"functionName"'',''target'',''isPersistent''] call [[BIS_fnc_MP]];
 +
 +
 +
== Adding a Function ==
 +
''WIP''
 +
=== Mission ===
 +
=== Addon ===
 +
 +
 +
== Writing a Function ==
 +
''WIP''
 +
 +
<!--
 
== Preview ==
 
== Preview ==
 
[[File:A3_functionwViewer.png|300px|thumb|right|In-game functions viewer]]
 
[[File:A3_functionwViewer.png|300px|thumb|right|In-game functions viewer]]
Line 138: Line 239:
 
# [[Event_Scripts|Init.sqs]]
 
# [[Event_Scripts|Init.sqs]]
 
# [[Triggers]]
 
# [[Triggers]]
 +
-->

Revision as of 13:05, 3 August 2013


Arma 3 Functions Library is pack of routine script functions available from anywhere in game. Main difference from older Functions Library is that it runs automatically and doesn't require Functions manager to be present.

Finding a Function

Functions Viewer

Before you can use a function, you first need to find it. The easies way is to access the Functions Viewer:

  • In editor, click on icon editor functions.png icon or press Ctrl + F
  • In mission, access the debug console (automatically visible in pause menu of an editor mission) and click on FUNCTIONS button.

Once in the Functions Viewer, you can filter all available functions by location, projects and categories.

When you find the desired function, look at the code preview on the right. Every function has a header where you can find basic description of its functionality including required arguments, returned values and sometimes examples of use.

Template:note


Calling a Function

Functions can be launched in mission, intro and outro using this call or spawn commands:

_returnedValue = arguments call functionName;
arguments spawn functionName;

Arguments

Arguments are data sent into the function, affecting its behavior.

They can be mandatory or optional.

  • Mandatory arguments are required for function to run. When missing, the function usually stops and throws an error.
  • Optional arguments allows more detailed configuration. If you dont send them, the function will use pre-defined default values.

Template:note


For example, let's take a look at BIS_fnc_endMission, a function which ends a mission with animated closing shot. This is what the header says:

/*
	Author: Karel Moricky

	Description:
	Ends mission with specific ending.

	Parameter(s):
		0 (Optional):
			STRING - end name (default: "end1")
			ARRAY in format [endName,ID], will be composed to "endName_ID" string
		1 (Optional): BOOL - true to end mission, false to fail mission (default: true)
		2 (Optional):
			BOOL - true for signature closing shot (default: true)
			NUMBER - duration of a simple fade out to black

	Returns:
	BOOL
*/

As you can see, all arguments are marked optional and you can call the function without them.

[] call BIS_fnc_endMission;
This will result in successfull ending of type "end1", preceeded with the signature closing shot.
["end2"] call BIS_fnc_endMission;
Set the ending type to "end2", while keeping the other arguments intact.
["end2",false,false] call BIS_fnc_endMission;
Fail the mission without any effect, using "end2" type.


However, what should you do if you want to set the only last argument without affecting the previous ones? The solution is simple - put an empty variable nil on their place.

[nil,nil,false] call BIS_fnc_endMission;
Disable the closing effects, but keep the other aguments intact (successful "end1").

Template:note

Returned Value

Functions executed by call command can return back a value. Let's take a look at BIS_fnc_sideName:

/*
	Author: Karel Moricky

	Description:
	Returns side name

	Parameter(s):
	0: SIDE or NUMBER - either side or side ID

	Returns:
	STRING
*/

The function returns a String - localized name of a side.

_westName = west call BIS_fnc_sideName;
Variable _westName will now be "BLUFOR" (or other name, based on selected language)

Multiplayer

Functions executed using call or spawn command will run only on the computer which triggered them. If you'd wish to execute a function remotely on specific clients, use BIS_fnc_MP function.

[arguments,"functionName",target,isPersistent] call BIS_fnc_MP;


Adding a Function

WIP

Mission

Addon

Writing a Function

WIP