Lesson 2

Next document to read and understand. Feel free to ask questions -
https://community.bistudio.com/wiki/Arma_3_Functions_Library

For a list of all prebuilt Arma 3 functions - Arma 3: Functions - Bohemia Interactive Community

As I mentioned in my Developer Introduction I learned a lot from reading the code behind the prebuilt Arma functions. The Function Viewer can be accessed through the Debug Console or Eden Editor (Tools > Functions Viewer or ALT-F).

Here is an example;
If you look up the function BIS_fnc_vehicleRoles in the Arma 3 wiki It will tell you how to use it, but it will not tell you how it was written.

Returns vehicle roles.
Syntax
Syntax:
vehicle call BIS_fnc_vehicleRoles
Parameters:
Object or String - vehicle itself or a classname
Return Value:
Array - to format [[role, path], [role, path], …] like this:
[
[“Driver”,],
[“Turret”,[0]],
[“Turret”,[0,0]],
[“Cargo”,[0]],
[“Cargo”,[1]],
(…)
]

For example, in the editor, you can place a Ghost Hawk with playable/player as the pilot and run the mission SP. Open the debug console and enter:

_veh =(vehicle player);
_roles = [_veh] call BIS_fnc_vehicleRoles;_roles

The Debug console will return

[[“Driver”,],[“Turret”,[0]],[“Turret”,[1]],[“Turret”,[2]],[“Cargo”,[0]],[“Cargo”,[1]],[“Cargo”,[2]],[“Cargo”,[3]],[“Cargo”,[4]],[“Cargo”,[5]],[“Cargo”,[6]],[“Cargo”,[7]]]

How did the function return this information, for that we will open the Functions Viewer.

Back in the editor, go to Tools>Functions Viewer.
Select configFile>A3>Vehicles>vehicleRoles
You will then see the code behind the function

/*
	Author: Karel Moricky

	Description:
	Returns vehicle roles

	Parameter(s):
		0: OBJECT or STRING

	Returns:
	ARRAY of ARRAYS in format [role,index],e.g. [["Driver",[]],["Turret",[0,1]],["Cargo",[0]]]
*/

private ["_vehicle","_roles","_cfgVehicle"];

_vehicle = _this param [0,objnull,[objnull,""]];
_roles = [];

if (typename _vehicle == typename objnull) then {_vehicle = typeof _vehicle;};

_cfgVehicle = configfile >> "cfgvehicles" >> _vehicle;

//--- Driver
if (getnumber (_cfgVehicle >> "hasdriver") > 0) then {
	_roles set [count _roles,["Driver",[]]];
};

//--- Turrets
{
	_roles set [count _roles,["Turret",_x]];
} foreach ([_vehicle,[]] call bis_fnc_getturrets);

//--- Cargo
for "_t" from 0 to (getnumber (_cfgVehicle >> "transportsoldier") - 1) do {
	_roles set [count _roles,["Cargo",[_t]]];
};

_roles

From reading through the default functions, not only did I learn more about what functions were available, but how to right code. I personally feel that it would have taken me much longer to learn Arma 3 basics if I had not gone through the default functions.