Functions Library – Take On Helicopters

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "bis_fnc_" to "BIS_fnc_")
m (Text replacement - "[[Image:" to "[[File:")
 
(4 intermediate revisions by the same user not shown)
Line 4: Line 4:
* for {{arma3}}, see [[Arma 3: Functions Library]]
* for {{arma3}}, see [[Arma 3: Functions Library]]
}}
}}
[[Functions Library 2.0]] 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.
[[Functions Library 2.0]] is pack of routine script functions available from anywhere in game.
The main difference from the older [[Functions Library]] is that it runs automatically and does not require Functions manager to be present.




Line 12: Line 13:


=== Singleplayer ===
=== Singleplayer ===
Functions can be launched in mission, intro and outro using this syntax:
Functions can be launched in mission, intro and outro using this syntax:
_fnc = [params] call functionName;
<sqf>_fnc = [params] call functionName;</sqf>
or
or
_fnc = [params] spawn functionName;
<sqf>_fnc = [params] spawn functionName;</sqf>


=== Multiplayer ===
=== Multiplayer ===


Functions replaces obsolete [[Arma 2: Multiplayer Framework]]. You can use [[BIS_fnc_MP]] to remotely execute function on specific clients and set them to be persistent, so they'll be executed automatically for client upon JIP.
Functions replaces the obsolete [[Arma 2: Multiplayer Framework]].
[[BIS_fnc_MP]] can be used to to remotely execute functions on specific clients and set them to be persistent, so they will be executed automatically for client upon JIP.


=== GUI ===
=== GUI ===


Anywhere outside running mission (user interface), refer to functions stored in UInamespace
Anywhere outside running mission (user interface), refer to functions stored in UInamespace
_fnc = [params] call (uinamespace getvariable 'functionName');
<sqf>_fnc = [params] call (uiNamespace getVariable "functionName");</sqf>
or
or
_fnc = [params] spawn (uinamespace getvariable 'functionName');
<sqf>_fnc = [params] spawn (uiNamespace getVariable "functionName");</sqf>




== In-game functions viewer ==
== In-Game Functions Viewer ==


[[Image:Take_On_Helicopters_Functions_Viewer.jpg|300px|thumb|right]]
[[File:Take_On_Helicopters_Functions_Viewer.jpg|300px|thumb|right]]
Use following code to display function library anywhere in game:
Use the following code to display function library anywhere in game:
[] call [[BIS_fnc_help]];
<sqf>[] call BIS_fnc_help;</sqf>


In the 3D Editor, you can find the Function Viewer in the Tools category of the menustrip [[File:icon editor functions.png|20px]]
In the 3D Editor, you can find the Function Viewer in the Tools category of the menustrip [[File:icon editor functions.png|20px]]
Line 43: Line 46:




== Adding new functions ==
== Add Functions ==


List of functions is defined in config under CfgFunctions container. New ones can be also added in description.ext file of mission or campaign.
The list of functions is defined in config under the {{hl|CfgFunctions}} container.
New ones can be also added in '''description.ext''' [[Description.ext|mission's]] or [[Campaign Description.ext|campaign's]] file.


  class CfgFunctions
  class CfgFunctions
  {
  {
  file = "<span style="color:DarkOrange;">hsim\ModulesCore_H\modules\functions</span>";
  file = "{{Color|DarkOrange|hsim\ModulesCore_H\modules\functions}}";
  class <span style="color:green;">BIS</span>
 
  class {{Color|green|BIS}}
  {
  {
  class <span style="color:crimson;">category1</span>
  class {{Color|crimson|category1}}
  {
  {
  class <span style="color:teal;">Test1</span> {description="Testing file 1"};
  class {{Color|teal|Test1}} { description = "Testing file 1" };
  };
  };
  };
  };
  class HSim
  class HSim
  {
  {
  tag = "<span style="color:green;">BIS</span>";
  tag = "{{Color|green|BIS}}";
  class <span style="color:crimson;">category2</span>
 
  class {{Color|crimson|category2}}
  {
  {
  file = "<span style="color:DarkOrange;">hsim\modules_h\functions</span>";
  file = "{{Color|DarkOrange|hsim\modules_h\functions}}";
  class <span style="color:teal;">Test2</span> {description="Testing file 2";};
  class {{Color|teal|Test2}} { description = "Testing file 2"; };
  class <span style="color:teal;">Test3</span> {description="Testing file 3"; file="<span style="color:DarkOrange;">test.sqf</span>"};
  class {{Color|teal|Test3}} { description = "Testing file 3"; file = "{{Color|DarkOrange|test.sqf}}" };
  class <span style="color:teal;">Test4</span> {description="Testing file 4 (FSM)"; ext="<span style="color:fuchsia;">.fsm</span>"};
  class {{Color|teal|Test4}} { description = "Testing file 4 (FSM)"; ext = "{{Color|fuchsia|.fsm}}" };
  };
  };
  };
  };
Line 71: Line 78:


* If 'file' path is not set for the given function, system will search for file in
* If 'file' path is not set for the given function, system will search for file in
**'' '<span style="color:DarkOrange;">file</span>\<span style="color:crimson">category</span>\fn_<span style="color:teal">function</span>.sqf"'' (if functions is defined in description.ext)
**'' '{{Color|DarkOrange|file}}\{{Color|crimson|category}}\fn_{{Color|teal|function}}.sqf"'' (if functions is defined in description.ext)
* When ''file='' parameter is defined in category root, all functions in given category will be searched for in this directory.
* When ''file ='' parameter is defined in category root, all functions in given category will be searched for in this directory.
* Default ''ext='' is .sqf. You can optionally use .fsm, but no other extensions are compatible. Define .fsm even when you're settings ''file='' leading directly to the file.
* Default ''ext ='' is .sqf. You can optionally use .fsm, but no other extensions are compatible. Define .fsm even when you're settings ''file ='' leading directly to the file.


Result is:
Result is:
* '''<span style="color:green;">BIS</span>_fnc_<span style="color:teal;">Test1</span>''' - will load script ''<span style="color:DarkOrange;">hsim\ModulesCore_H\modules\functions</span>\<span style="color:crimson;">category1</span>\<span style="color:teal;">test1</span>.sqf'' from functions directory (see above)
* '''{{Color|green|BIS}}_fnc_{{Color|teal|Test1}}''' - will load script ''{{Color|DarkOrange|hsim\ModulesCore_H\modules\functions}}\{{Color|crimson|category1}}\{{Color|teal|test1}}.sqf'' from functions directory (see above)
* '''<span style="color:green;">BIS</span>_fnc_<span style="color:teal;">Test2</span>''' - will load script ''<span style="color:DarkOrange;">hsim\modules_h\functions</span>\<span style="color:crimson;">category2</span>\<span style="color:teal;">Test2</span>.sqf''
* '''{{Color|green|BIS}}_fnc_{{Color|teal|Test2}}''' - will load script ''{{Color|DarkOrange|hsim\modules_h\functions}}\{{Color|crimson|category2}}\{{Color|teal|Test2}}.sqf''
* '''<span style="color:green;">BIS</span>_fnc_<span style="color:teal;">Test3</span>''' - will load script ''<span style="color:DarkOrange;">test.sqf</span>'' from mission directory
* '''{{Color|green|BIS}}_fnc_{{Color|teal|Test3}}''' - will load script ''{{Color|DarkOrange|test.sqf}}'' from mission directory
* '''<span style="color:green;">BIS</span>_fnc_<span style="color:teal;">Test4</span>''' - will load FSM ''<span style="color:DarkOrange;">hsim\modules_h\functions</span>\<span style="color:crimson;">category2</span>\<span style="color:teal;">Test4</span><span style="color:fuchsia;">.fsm</span>''
* '''{{Color|green|BIS}}_fnc_{{Color|teal|Test4}}''' - will load FSM ''{{Color|DarkOrange|hsim\modules_h\functions}}\{{Color|crimson|category2}}\{{Color|teal|Test4}}{{Color|fuchsia|.fsm}}''




Line 87: Line 94:


Use debug functions/commands to register params, display errors and log messages. Printed output of these functions automatically contains name of function from which it was called.
Use debug functions/commands to register params, display errors and log messages. Printed output of these functions automatically contains name of function from which it was called.
{{Feature|important|Usage of following functions/commands is mandatory:
{{Feature|important|
Usage of the following commands and functions is mandatory:
* [[param]]
* [[param]]
* [[params]]
* [[params]]
Line 96: Line 104:


Examples of debug outputs:
Examples of debug outputs:
{{codecomment|"Helicopter class is empty." call BIS_fnc_halt;}}
<sqf>
[3104] Log: HALT: [BIS_fnc_heliportHeliAddMission] Helicopter class is empty.
"Helicopter class is empty." call BIS_fnc_halt; // [3104] Log: HALT: [BIS_fnc_heliportHeliAddMission] Helicopter class is empty.
{{codecomment|_mission <nowiki>=</nowiki> [[param]] [0,worldName,[""]];}}
[3104] Log: ERROR: [BIS_fnc_endMission] 0: HSim_Player is type OBJECT, must be STRING. "United_States_H" used instead.
{{codecomment|["Helicopter '%1' not found.",_heliPlayer] call BIS_fnc_error;}}
[3104] Log: ERROR: [BIS_fnc_heliportHeliAddMission] Helicopter 'MYHELICOPTER' not found.
{{codecomment|42 call BIS_fnc_log;}}
[3104] array ["Log: [BIS_fnc_heliportInit] ",42]
{{codecomment|["Random number is %1",random 999] call BIS_fnc_log;}}
[3104] Log: [BIS_fnc_heliportInit] Random number is 808.768


_mission = param [0, worldName, [""]]; // [3104] Log: ERROR: [BIS_fnc_endMission] 0: HSim_Player is type OBJECT, must be STRING. "United_States_H" used instead.
["Helicopter '%1' not found.", _heliPlayer] call BIS_fnc_error; // [3104] Log: ERROR: [BIS_fnc_heliportHeliAddMission] Helicopter 'MYHELICOPTER' not found.
42 call BIS_fnc_log; // [3104] array ["Log: [BIS_fnc_heliportInit] ", 42]
["Random number is %1",random 999] call BIS_fnc_log; // [3104] Log: [BIS_fnc_heliportInit] Random number is 808.768
</sqf>


=== Debug Mode ===
=== Debug Mode ===
Developers can access several debug modes using ''[[BIS_fnc_functionsDebug]]'' function.
Developers can access several debug modes using ''[[BIS_fnc_functionsDebug]]'' function.
# '''No debug'''
# '''No debug'''
Line 122: Line 127:


=== Debug Variables ===
=== Debug Variables ===
Store following variables into profileNameSpace to toggle various debug options:
Store following variables into profileNameSpace to toggle various debug options:
* '''BIS_fnc_initRecompileEditor''' - recompiles functions every time you click on 'Preview' button in editor ensuring changes made in functions are present on mission start.
* '''BIS_fnc_initRecompileEditor''' - recompiles functions every time you click on 'Preview' button in editor ensuring changes made in functions are present on mission start.
Line 142: Line 148:
# Init.sqs
# Init.sqs
# Triggers
# Triggers
{{Feature|informative|See {{Link|Initialisation Order}}.}}


{{GameCategory|tkoh|Editing}}
{{GameCategory|tkoh|Editing}}
[[Category:Functions Library]]

Latest revision as of 00:11, 21 November 2023

This page is about Take On Helicopters Functions Library system.

Functions Library 2.0 is pack of routine script functions available from anywhere in game. The main difference from the older Functions Library is that it runs automatically and does not require Functions manager to be present.


Usage

params are parameters required by given function. If you wish to skip a param (e.g. leave it is default value), use nil on its index (valid only if BIS_fnc_param is used by the function).

Singleplayer

Functions can be launched in mission, intro and outro using this syntax:

_fnc = [params] call functionName;

or

_fnc = [params] spawn functionName;

Multiplayer

Functions replaces the obsolete Arma 2: Multiplayer Framework. BIS_fnc_MP can be used to to remotely execute functions on specific clients and set them to be persistent, so they will be executed automatically for client upon JIP.

GUI

Anywhere outside running mission (user interface), refer to functions stored in UInamespace

_fnc = [params] call (uiNamespace getVariable "functionName");

or

_fnc = [params] spawn (uiNamespace getVariable "functionName");


In-Game Functions Viewer

Take On Helicopters Functions Viewer.jpg

Use the following code to display function library anywhere in game:

In the 3D Editor, you can find the Function Viewer in the Tools category of the menustrip icon editor functions.png

Features:

  • Listing through all functions from config or description.ext files.
  • Displaying name, path, description and code of selected functions.
  • Code can be easily copied to clipboard.


Add Functions

The list of functions is defined in config under the CfgFunctions container. New ones can be also added in description.ext mission's or campaign's file.

class CfgFunctions
{
	file = "hsim\ModulesCore_H\modules\functions";
	class BIS
	{
		class category1
		{
			class Test1		{ description = "Testing file 1" };
		};
	};
	class HSim
	{
		tag = "BIS";
		class category2
		{
			file = "hsim\modules_h\functions";
			class Test2		{ description = "Testing file 2"; };
			class Test3		{ description = "Testing file 3"; file = "test.sqf" };
			class Test4		{ description = "Testing file 4 (FSM)"; ext = ".fsm" };
		};
	};
};
  • If 'file' path is not set for the given function, system will search for file in
    • 'file\category\fn_function.sqf" (if functions is defined in description.ext)
  • When file = parameter is defined in category root, all functions in given category will be searched for in this directory.
  • Default ext = is .sqf. You can optionally use .fsm, but no other extensions are compatible. Define .fsm even when you're settings file = leading directly to the file.

Result is:

  • BIS_fnc_Test1 - will load script hsim\ModulesCore_H\modules\functions\category1\test1.sqf from functions directory (see above)
  • BIS_fnc_Test2 - will load script hsim\modules_h\functions\category2\Test2.sqf
  • BIS_fnc_Test3 - will load script test.sqf from mission directory
  • BIS_fnc_Test4 - will load FSM hsim\modules_h\functions\category2\Test4.fsm


Debugging

Debug Functions

Use debug functions/commands to register params, display errors and log messages. Printed output of these functions automatically contains name of function from which it was called.

Usage of the following commands and functions is mandatory:

Examples of debug outputs:

"Helicopter class is empty." call BIS_fnc_halt; // [3104] Log: HALT: [BIS_fnc_heliportHeliAddMission] Helicopter class is empty. _mission = param [0, worldName, [""]]; // [3104] Log: ERROR: [BIS_fnc_endMission] 0: HSim_Player is type OBJECT, must be STRING. "United_States_H" used instead. ["Helicopter '%1' not found.", _heliPlayer] call BIS_fnc_error; // [3104] Log: ERROR: [BIS_fnc_heliportHeliAddMission] Helicopter 'MYHELICOPTER' not found. 42 call BIS_fnc_log; // [3104] array ["Log: [BIS_fnc_heliportInit] ", 42] ["Random number is %1",random 999] call BIS_fnc_log; // [3104] Log: [BIS_fnc_heliportInit] Random number is 808.768

Debug Mode

Developers can access several debug modes using BIS_fnc_functionsDebug function.

  1. No debug
    • Default
  2. Save script map
    • Variable _fnc_scriptMap tracking script execution progress is stored in function header
  3. Save and log script map
    • Variable _fnc_scriptMap tracking script execution progress is stored in functions header and it is printed to debug log.

Debug Variables

Store following variables into profileNameSpace to toggle various debug options:

  • BIS_fnc_initRecompileEditor - recompiles functions every time you click on 'Preview' button in editor ensuring changes made in functions are present on mission start.


Meta Variables

System is adding header with basic meta data to all functions. Following local variables are defined there:

  • _fnc_scriptName: STRING - Function name (<tag>_fnc_<name>)
  • _fnc_scriptNameParent: STRING - Name of function from which current one was called (_fnc_scriptName used when not defined)
  • _fnc_scriptMap: ARRAY - List of all parent scripts (available only in debug mode 1 and higher, see above).
Please do not modify these values!

Initialization Order

  1. Functions
  2. Init Event Handlers
  3. Mission.sqm
  4. Init.sqf
  5. Init.sqs
  6. Triggers