ACE3/addons/common/functions/fnc_getDefinedVariable.sqf

40 lines
869 B
Plaintext
Raw Normal View History

#include "..\script_component.hpp"
2015-09-20 22:28:25 +00:00
/*
* Author: Glowbal
* Grabs a variable. If variable has not been set, attempts to use default defined value
2015-01-16 23:21:47 +00:00
*
2015-09-20 22:28:25 +00:00
* Arguments:
* 0: unit <OBJECT>
* 1: Variable Name <STRING>
*
* Return Value:
* Value of variable or default value, if the variable is undefined <ANY>
*
* Example:
* [bob, "var"] call ace_common_fnc_getDefinedVariable
*
2015-09-20 22:28:25 +00:00
* Public: No
2015-01-16 23:21:47 +00:00
*/
2015-09-20 22:28:25 +00:00
params ["_unit", "_variable", "_defaultValue"];
2015-01-16 23:21:47 +00:00
private _value = _unit getVariable _variable;
2015-01-16 23:21:47 +00:00
2015-09-20 22:28:25 +00:00
if (isNil "_value") then {
if (!isNil "_defaultValue") then {
_value = _defaultValue;
2015-01-18 19:09:19 +00:00
} else {
2015-12-12 16:26:47 +00:00
private _definedVariable = _variable call FUNC(getDefinedVariableInfo);
2015-09-20 22:28:25 +00:00
2015-01-18 19:09:19 +00:00
if (count _definedVariable > 1) then {
_value = _definedVariable select 1;
};
};
2015-09-20 22:28:25 +00:00
if (isNil "_value") then {
2015-01-18 19:09:19 +00:00
_value = 0;
};
2015-01-16 23:21:47 +00:00
};
2015-09-20 22:28:25 +00:00
_value