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>
|
|
|
|
*
|
|
|
|
* Public: No
|
2015-01-16 23:21:47 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-09-20 22:28:25 +00:00
|
|
|
params ["_unit", "_variable", "_defaultValue"];
|
2015-01-16 23:21:47 +00:00
|
|
|
|
|
|
|
private "_value";
|
2015-09-20 22:28:25 +00:00
|
|
|
_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 {
|
|
|
|
private "_definedVariable";
|
2015-09-20 22:28:25 +00:00
|
|
|
_definedVariable = [_variable] call FUNC(getDefinedVariableInfo);
|
|
|
|
|
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
|