getNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(upd. links)
m (Text replacement - "config / name" to "a / b")
 
(100 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma |= Game name
|game1= arma1
|version1= 1.00


|1.00|= Game version
|game2= arma2
____________________________________________________________________________________________
|version2= 1.00


| Extract number from config entry. |= Description
|game3= arma2oa
____________________________________________________________________________________________
|version3= 1.50


| [[Number]] <nowiki>=</nowiki>'''getNumber''' config |= Syntax
|game4= tkoh
|version4= 1.00


|p1= config: [[Config]] |= Parameter 1
|game5= arma3
|version5= 0.50


| [[Number]] |= Return value
|gr1= Config
____________________________________________________________________________________________
 
|x1= <pre>_value = getNumber (configFile >> "CfgVehicles" >> "Thing" >> "maxSpeed")</pre> |= Example 1
____________________________________________________________________________________________


| [[configFile]], [[config/name]], [[configName]], [[count config]], [[getArray]], [[getText]], [[inheritsFrom]], [[isArray]], [[isClass]], [[isNumber]], [[isText]], [[select config]] |= See also
|descr= Extract number from config entry.


|s1= [[getNumber]] config
|p1= config: [[Config]]
|r1= [[Number]]
|x1= <sqf>_value = getNumber (configFile >> "CfgVehicles" >> "Thing" >> "maxSpeed");</sqf>
|seealso= [[configFile]] [[a / b]] [[configName]] [[count]] [[getArray]] [[getText]] [[inheritsFrom]] [[isArray]] [[isClass]] [[isNumber]] [[isText]] [[select]]
}}
{{Note
|user= Donnervogel
|timestamp= 20070303044500
|text= Use [[getNumber]] to get [[Boolean|boolean]] values from a config entry. 1 equals [[true]], 0 equals [[false]].
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= Loki
<!-- Note Section BEGIN -->
|timestamp= 20110913004400
<dd class="notedate">Posted on 04:45, 3 March 2007 (CET)</dd>
|text= With an not existing entry, [[getNumber]] returns 0.
<dt class="note>'''[[User:Donnervogel|Donnervogel]]'''</dt><dd class="note">use getNumber to get [[Boolean|boolean]] values from a config file. 1 equals true, 0 equals false and if no value is found (when a valid variable is undefined) 0.67 is returned.</dd>
}}
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
{{Note
[[Category:Scripting Commands|GETNUMBER]]
|user= ffur2007slx2_5
[[Category:Scripting Commands ArmA|GETNUMBER]]
|timestamp= 20140328075300
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
|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>
[[Category:Command_Group:_System_Commands|{{uc:{{PAGENAME}}}}]]
Traditional workaround:
[[Category:Scripting Commands VBS2|{{uc:{{PAGENAME}}}}]]
<sqf>
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 };
};
</sqf>
'''Recommended workaround:'''
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgData;</sqf>
To return default value once entry was not found, we can use [[BIS_fnc_returnConfigEntry]] instead of [[BIS_fnc_getCfgData]].
<sqf>[(configFile >> "CannonFire" >> "LightExp"),"lifeTime",0] call BIS_fnc_returnConfigEntry; // 0.5</sqf>
To compose collected [[Number]] into [[Array]], use [[BIS_fnc_getCfgDataArray]] instead.
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataArray;</sqf>
To retype collected [[Number]] into [[Boolean]], use [[BIS_fnc_getCfgDataBool]]. Anything bigger than 0 is true, otherwise false.
<sqf>(configFile >> "CfgVehicles" >> _SomeAddonClassName >> "DestructionEffects" >> "Smoke1" >> "type") call BIS_fnc_getCfgDataBool;</sqf>
}}

Latest revision as of 14:22, 30 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 a / b 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;