getNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<code>([^<]*)\[\[([^|]+\|)(\/?\/?>?>?<?=?)\]\]([^<]*) *<\/code>" to "<code>$1$3$4</code>")
m (Some wiki formatting)
Line 26: Line 26:
|r1= [[Number]]
|r1= [[Number]]


|x1= <code>_value = getNumber (configFile >> "CfgVehicles" >> "Thing" >> "maxSpeed");</code>
|x1= <sqf>_value = getNumber (configFile >> "CfgVehicles" >> "Thing" >> "maxSpeed");</sqf>


|seealso= [[configFile]] [[config / name]] [[configName]] [[count]] [[getArray]] [[getText]] [[inheritsFrom]] [[isArray]] [[isClass]] [[isNumber]] [[isText]] [[select]]
|seealso= [[configFile]] [[config / name]] [[configName]] [[count]] [[getArray]] [[getText]] [[inheritsFrom]] [[isArray]] [[isClass]] [[isNumber]] [[isText]] [[select]]
}}
}}


<dl class="command_description">
{{Note
|user= Donnervogel
|timestamp= 20070303044500
|text= Use [[getNumber]] to get [[Boolean|boolean]] values from a config entry. 1 equals [[true]], 0 equals [[false]].
}}
 
{{Note
|user= Loki
|timestamp= 20110913004400
|text= With an not existing entry, [[getNumber]] returns 0.
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on 04:45, 3 March 2007 (CET)</dd>
|user= ffur2007slx2_5
<dt class="note">[[User:Donnervogel|Donnervogel]]</dt>
|timestamp= 20140328075300
<dd class="note">
|text= ({{arma3}} 1.14), It's recommended to use [[BIS_fnc_getCfgData]] or [[BIS_fnc_returnConfigEntry]] to get variable cfg data rather than conditioning via [[isNumber]], [[isText]], [[isArray]], [[getNumber]], [[getText]] and [[getArray]] combination. <br>
Use getNumber to get [[Boolean|boolean]] values from a config entry. 1 equals [[true]], 0 equals [[false]].
<dd class="notedate">Posted on 13 September 2011</dd>
<dt class="note">[[User:Loki|Loki]]</dt>
<dd class="note">
With an not existing entry, [[getNumber]] returns 0.
<dd class="notedate">Posted on Mar 28, 2014 - 07:53</dd>
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]</dt>
<dd class="note">
({{arma3}} 1.14), It's recommended to use [[BIS_fnc_getCfgData]] or [[BIS_fnc_returnConfigEntry]] to get variable cfg data rather than conditioning via [[isNumber]], [[isText]], [[isArray]], [[getNumber]], [[getText]] and [[getArray]] combination. <br>
Traditional workaround:
Traditional workaround:
<code>_cfg = configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type"
<sqf>
switch ( [[true ]]) do
private _cfg = configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type";
switch (true) do
{
{
case (isNumber _cfg): {getNumber _cfg};
case (isNumber _cfg): { getNumber _cfg };
case (isText _cfg): {getText _cfg};
case (isText _cfg): { getText _cfg };
case (isArray _cfg): {getArray _cfg;};
case (isArray _cfg): { getArray _cfg };
default {nil};
default { nil };
};</code>
};
</sqf>
'''Recommended workaround:'''
'''Recommended workaround:'''
<code>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgData;
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgData;</sqf>
</code>
To return default value once entry was not found, we can use [[BIS_fnc_returnConfigEntry]] instead of [[BIS_fnc_getCfgData]].
To return default value once entry was not found, we can use [[BIS_fnc_returnConfigEntry]] instead of [[BIS_fnc_getCfgData]].
<code>[(configFile >> "CannonFire" >> "LightExp"),"lifeTime",0] call BIS_fnc_returnConfigEntry;//0.5
<sqf>[(configFile >> "CannonFire" >> "LightExp"),"lifeTime",0] call BIS_fnc_returnConfigEntry; // 0.5</sqf>
</code>
To compose collected [[Number]] into [[Array]], use [[BIS_fnc_getCfgDataArray]] instead.
To compose collected [[Number]] into [[Array]], use [[BIS_fnc_getCfgDataArray]] instead.
<code>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataArray;
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataArray;</sqf>
</code>
To retype collected [[Number]] into [[Boolean]], use [[BIS_fnc_getCfgDataBool]]. Anything bigger than 0 is true, otherwise false.  
To retype collected [[Number]] into [[Boolean]], use [[BIS_fnc_getCfgDataBool]]. Anything bigger than 0 is true, otherwise false.  
<code>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataBool;
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataBool;</sqf>
</code>
}}
</dl>

Revision as of 11:16, 13 May 2022

Hover & click on the images for description

Description

Description:
Extract number from config entry.
Groups:
Config

Syntax

Syntax:
getNumber config
Parameters:
config: Config
Return Value:
Number

Examples

Example 1:
_value = getNumber (configFile >> "CfgVehicles" >> "Thing" >> "maxSpeed");

Additional Information

See also:
configFile config / name configName count getArray getText inheritsFrom isArray isClass isNumber isText select

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Donnervogel - c
Posted on Mar 03, 2007 - 04:45 (UTC)
Use getNumber to get boolean values from a config entry. 1 equals true, 0 equals false.
Loki - c
Posted on Sep 13, 2011 - 00:44 (UTC)
With an not existing entry, getNumber returns 0.
ffur2007slx2_5 - c
Posted on Mar 28, 2014 - 07:53 (UTC)
(Arma 3 1.14), It's recommended to use BIS_fnc_getCfgData or BIS_fnc_returnConfigEntry to get variable cfg data rather than conditioning via isNumber, isText, isArray, getNumber, getText and getArray combination.
Traditional workaround:
private _cfg = configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type"; switch (true) do { case (isNumber _cfg): { getNumber _cfg }; case (isText _cfg): { getText _cfg }; case (isArray _cfg): { getArray _cfg }; default { nil }; };
Recommended workaround:
(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgData;
To return default value once entry was not found, we can use BIS_fnc_returnConfigEntry instead of BIS_fnc_getCfgData.
[(configFile >> "CannonFire" >> "LightExp"),"lifeTime",0] call BIS_fnc_returnConfigEntry; // 0.5
To compose collected Number into Array, use BIS_fnc_getCfgDataArray instead.
(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataArray;
To retype collected Number into Boolean, use BIS_fnc_getCfgDataBool. Anything bigger than 0 is true, otherwise false.
(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataBool;