configClasses: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "IT07" to "Nelis.75733126")
 
(88 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma3 |= Game name
|game1= arma3
|version1= 1.24


|1.24|= Game version
|gr1= Config


____________________________________________________________________________________________
|descr= Returns an array of config entries which meet criteria in condition code. Command iterates through all available config sub classes of the given config class. Current looked at config is stored in _x variable (similar to alternative [[count]] command implementation). Condition has to return [[true]] in order for the looked at config to be added to the resulting array. Slightly faster than [[configProperties]], but doesn't account for config properties or inherited entries.
{{Feature|important|
* The condition code passed to [[configClasses]] should only be used for '''simple filter expressions''' and nothing more
* Do not use {{hl|"[[isClass]] [[Magic Variables#x|_x]]"}} in the condition. The engine does this check already<br><br>
* {{arma3}} v2.02 brought specific engine optimisations for the following conditions:
** {{hl|"[[true]]"}}
** {{hl|"[[getNumber]] ([[Magic Variables#x|_x]] >> 'scope') > 0"}}}}


| Returns an array of config entries which meet criteria in condition code. Command iterates through all available config sub classes of the given config class. Current looked at config is stored in _x variable (similar to alternative [[count]] command implementation). Condition has to return [[true]] in order for the looked at config to be added to the resulting array. |= Description
|s1= condition [[configClasses]] config
____________________________________________________________________________________________


| condition '''configClasses''' config |= Syntax
|p1= condition: [[String]]


|p1= condition: [[String]] |= Parameter 1
|p2= config: [[Config]]
|p2= config: [[Config]] |= Parameter 1


| [[Array]] - Array of [[Config]]s |= Return value
|r1= [[Array]] - array of [[Config]]s
____________________________________________________________________________________________
 
|x1= List all CfgVehicles class names in .rpt file: <code>_configs = "[[diag_log]] [[configName]] _x; [[true]]" [[configClasses]] ([[configFile]] >> "CfgVehicles");</code> |= Example 1


|x2= Return all classes that can transport 10 and more soldiers: <code>_transporters = "[[getNumber]] (_x >> 'transportSoldier') >= 10" [[configClasses]] ([[configFile]] >> "CfgVehicles");</code> |= Example 2
|x1= collect all CfgVehicles configs:
<sqf>_configs = "true" configClasses (configFile >> "CfgVehicles");</sqf>


|x3= Return all classes that inherit from 'RscText': <code>[[hint]] [[str]] ("[[inheritsFrom]] _x == ([[configFile]] >> 'RscText')" [[configClasses]] [[configFile]]);</code> |= Example 3
|x2= Return all classes that can transport 10 and more soldiers:
<sqf>_transporters = "getNumber (_x >> 'transportSoldier') >= 10" configClasses (configFile >> "CfgVehicles");</sqf>


|x4= Generate an array of west (useable) vehicles and spawn them around the player: <code>private ["_path","_cfgArray","_veh"];
|x3= Return all classes that inherit from 'RscText':
_path = (configFile >> "CfgVehicles");
<sqf>hint str ("inheritsFrom _x == (configFile >> 'RscText')" configClasses configFile);</sqf>
_cfgArray = "(
(getNumber (_x >> 'scope') >= 2) &&
{getNumber (_x >> 'side') == 1 &&
{getText (_x >> 'vehicleClass') in ['Armored', 'Car', 'Air']
}
}
)" configClasses _path;


{
|seealso= [[Config]] [[configFile]] [[missionConfigFile]] [[configProperties]] [[configHierarchy]]
_veh = createVehicle [configName _x, getPosATL player, [], 0, "None"];
}}
sleep 1;
} forEach _cfgArray;</code> |= Example 4


____________________________________________________________________________________________
{{Note
|user= Iceman77
|timestamp= 20141019122400
|text= A fantastic way to filter stuff. eg:
<sqf>// create an array of west vehicles and spawn then in front of the player in rows of 5


| [[Config]], [[configFile]], [[missionConfigFile]] |= See also
private ["_cfgArray", "_xPos", "_yPos", "_veh"];


}}
_cfgArray = "(
(getNumber (_x >> 'scope') >= 2) &&
{
getNumber (_x >> 'side') == 1 &&
{ getText (_x >> 'vehicleClass') in ['Armored', 'Car', 'Air'] }
}
)" configClasses (configFile >> "CfgVehicles");


<h3 style="display:none">Notes</h3>
_xPos = 0;
<dl class="command_description">
_yPos = 0;
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on Jul 19, 2014 - 20:08
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
(ArmA3 1.24) It is recommended to use [[configClasses]] instead of [[BIS_fnc_getCfgSubClasses]] and [[BIS_fnc_uniqueClasses]] on subclasses collection or conditional selection.
<code>
_faces = "[[true]]" [[configClasses]] ([[configFile]] >> "Cfgfaces");
//same as: _faces = (configfile >> "CfgFaces") [[call]] [[BIS_fnc_getCfgSubClasses]];
</code>
<code>
//Extract all animals:
animals = "(([[configName]] _x) [[isKindOf]] 'animal')" [[configClasses]] ([[configFile]] >> "CfgVehicles");
/*same as:
aniamls = [];
[([[configFile]] >> "CfgVehicles"),{
[[if]] (([[configName]] _this) [[isKindOf]] “animal”) [[then]] {
  animals [[set]] [ [[count]] animals, _this]
  }
}
] [[call]] [[BIS_fnc_uniqueClasses]];*/
</code>
Return nested subclasses, currently still [[BIS_fnc_returnChildren]]
<code>
//Return all nested config classes.<br>
[([[configFile]] >> "CfgFaces"),1, [[true]], [[true]] ] [[call]] [[BIS_fnc_returnChildren]];
</code>
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
{
_yPos = _yPos + 20;
_veh = createVehicle [(configName _x), player modelToWorld [_xPos, _yPos, 0], [], 0, "NONE"];
if (_yPos >= 100) then
{
_yPos = 0;
_xPos = _xPos + 20;
};
} forEach _cfgArray;</sqf>
}}


{{Note
|user= Benargee
|timestamp= 20160528202800
|text= [[configClasses]] does not account for inherited subclasses, use [[configProperties]] with [[isClass]] filter instead
<sqf>configProperties [_config, "isClass _x", true];</sqf>
}}


[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
{{Note
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
|user= Nelis.75733126
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
|timestamp= 20170528091800
|text= this will get a list of ALL locations on the currently loaded world
<sqf>( "true" configClasses (configFile >> "CfgWorlds" >> worldName >> "names" ) ) apply {
// change each config entry into a location
nearestLocation [
getArray ( _x >> "position" ),
getText ( _x >> "type" )
]
};</sqf>
}}

Latest revision as of 19:00, 16 April 2024

Hover & click on the images for description

Description

Description:
Returns an array of config entries which meet criteria in condition code. Command iterates through all available config sub classes of the given config class. Current looked at config is stored in _x variable (similar to alternative count command implementation). Condition has to return true in order for the looked at config to be added to the resulting array. Slightly faster than configProperties, but doesn't account for config properties or inherited entries.
  • The condition code passed to configClasses should only be used for simple filter expressions and nothing more
  • Do not use "isClass _x" in the condition. The engine does this check already

  • Arma 3 v2.02 brought specific engine optimisations for the following conditions:
Groups:
Config

Syntax

Syntax:
condition configClasses config
Parameters:
condition: String
config: Config
Return Value:
Array - array of Configs

Examples

Example 1:
collect all CfgVehicles configs:
_configs = "true" configClasses (configFile >> "CfgVehicles");
Example 2:
Return all classes that can transport 10 and more soldiers:
_transporters = "getNumber (_x >> 'transportSoldier') >= 10" configClasses (configFile >> "CfgVehicles");
Example 3:
Return all classes that inherit from 'RscText':
hint str ("inheritsFrom _x == (configFile >> 'RscText')" configClasses configFile);

Additional Information

See also:
Config configFile missionConfigFile configProperties configHierarchy

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
Iceman77 - c
Posted on Oct 19, 2014 - 12:24 (UTC)
A fantastic way to filter stuff. eg:
// create an array of west vehicles and spawn then in front of the player in rows of 5 private ["_cfgArray", "_xPos", "_yPos", "_veh"]; _cfgArray = "( (getNumber (_x >> 'scope') >= 2) && { getNumber (_x >> 'side') == 1 && { getText (_x >> 'vehicleClass') in ['Armored', 'Car', 'Air'] } } )" configClasses (configFile >> "CfgVehicles"); _xPos = 0; _yPos = 0; { _yPos = _yPos + 20; _veh = createVehicle [(configName _x), player modelToWorld [_xPos, _yPos, 0], [], 0, "NONE"]; if (_yPos >= 100) then { _yPos = 0; _xPos = _xPos + 20; }; } forEach _cfgArray;
Benargee - c
Posted on May 28, 2016 - 20:28 (UTC)
configClasses does not account for inherited subclasses, use configProperties with isClass filter instead
configProperties [_config, "isClass _x", true];
Nelis.75733126 - c
Posted on May 28, 2017 - 09:18 (UTC)
this will get a list of ALL locations on the currently loaded world
( "true" configClasses (configFile >> "CfgWorlds" >> worldName >> "names" ) ) apply { // change each config entry into a location nearestLocation [ getArray ( _x >> "position" ), getText ( _x >> "type" ) ] };