Jump to content
davidoss

[Solved]Trouble with gathering classes from configfile

Recommended Posts

Hi.

 

Have written function to get all factions of given side from configfile.

	_getsideFactions = {

		params ["_side", "_array", "_entry", "_i", "_entryside"];
		
		_array = [];

		for "_i" from 0 to (count (configfile >> "CfgFactionClasses")) -1 do {
		
			_entry = configname ((configfile >> "CfgFactionClasses") select _i);
			_entryside = getNumber (configfile >> "CfgFactionClasses" >> _entry >> "side");

			if (_entryside == _side) then {
			
				_array pushback _entry;
			
			};

		};
	_array
	};

Called by:

_factions = [0] call _getsideFactions; // 0 east, 1 west, 2 independent

Function is returning :

 

 

["access","OPF_F","OPF_G_F","CUP_O_RU","CUP_O_ChDKZ","CUP_O_TK","CUP_O_TK_MILITIA","CUP_O_SLA","BWA3_Faction"]

 

Unfortunately this is also throwing out an error :

 

 

'access/' is not a class ('side' accessed)

 

Yes there are "access" index in returned array but why? access is a sub entry from configfile >> "CfgFactionClasses"

 

access = 1;

 

Why this is not working right?

Please help!

Share this post


Link to post
Share on other sites

Added if (isClass), I think that will do the trick

	_getsideFactions = 
	{
		params ["_side", "_array", "_entry", "_i", "_entryside"];		
		_array = [];
		
		for "_i" from 0 to (count (configfile >> "CfgFactionClasses")) -1 do 
		{
			_entry = configname ((configfile >> "CfgFactionClasses") select _i);
			if (isClass _entry) then 
			{
				_entryside = getNumber (configfile >> "CfgFactionClasses" >> _entry >> "side");
				if (_entryside == _side) then 
				{				
					_array pushback _entry;				
				};
			};
		};
		_array
	}; 

Share this post


Link to post
Share on other sites

Nice try but obviously the

configname ((configfile >> "CfgFactionClasses") select _i) is not a class 

just string but i think you point me in the right direction.

 

 

Thank you

Share this post


Link to post
Share on other sites

How about configClasses?

_checkSide = 1; //replace with sideID of choice
_factions = "getNumber (_x >> 'side') isEqualTo _checkSide" configClasses (configfile >> "CfgFactionClasses");

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

This is just perfect solution.

Very quick and clean

	_getsideFactions = {
	
		params ["_side", "_array"];
		
		_array = [];
		{
			_array pushback	(configName _x);
		} forEach ("getNumber (_x >> 'side') isEqualTo _side" configClasses (configfile >> "CfgFactionClasses"));
		
		_array
	};

the same solution can be used to gather all units classnames of given faction:

	_getClasses = {

		params ["_faction", "_array"];
		_array = [];
		
		{
			if ((configName _x) isKindoF "CAManBase") then {
				_array pushback	(configName _x);
			};
		} forEach ("getText (_x >> 'faction') == _faction" configClasses (configfile >> "CfgVehicles"));
		
		_array
	};

Thank you Grumpy Old Man

  • Like 2

Share this post


Link to post
Share on other sites

This is very handy davidoss. Thank You.
I've been putting together a developer mission filled with many of the tools I often need and added your functions with slight modifications to it.
Added a filter to only list the classnames available in the editor and exclude private and base classes.
It prints to .rpt the faction followed by men classes belonging to that faction.

getSideFactions = {
    params ["_side","_factionList","_faction","_men"];
    _factionList = [];

    {
        _factionList pushback (configName _x);
    } forEach ("getNumber (_x >> 'side') isEqualTo _side" configClasses (configfile >> "CfgFactionClasses"));

    {
        _faction = _x;
        diag_log text format ["Faction: %1", _faction];
        _men = [_faction] call getClasses;
    } forEach _factionList;

    true
};

getClasses = {
    params ["_faction","_menList","_className","_cfg","_scope"];
    _menList = [];

    {
        if ((configName _x) isKindoF "CAManBase") then {
            _classname = (configName _x);
            _cfg = configfile >> "CfgVehicles" >> (configName _x);
            _scope = getNumber(_cfg >> "scope");
            if (_scope >= 2) then { _menList pushBack (configName _x); };
        };
    } forEach ("getText (_x >> 'faction') == _faction" configClasses (configfile >> "CfgVehicles"));

    diag_log text format ["Men List: %1", _menList];

    true
};

player addaction ["Print East Factions/Men", {[0] call getSideFactions;}];
player addaction ["Print West Factions/Men", {[1] call getSideFactions;}];
player addaction ["Print Resistance Factions/Men", {[2] call getSideFactions;}]; 
player addaction ["Print Civilian Factions/Men", {[3] call getSideFactions;}];

Share this post


Link to post
Share on other sites

This is just perfect solution.

Very quick and clean

	_getsideFactions = {
	
		params ["_side", "_array"];
		
		_array = [];
		{
			_array pushback	(configName _x);
		} forEach ("getNumber (_x >> 'side') isEqualTo _side" configClasses (configfile >> "CfgFactionClasses"));
		
		_array
	};

 

 

Also works fine:

	private _side = 1;
	private _factions = "getNumber (_x >> 'side') isEqualTo _side" configClasses (configfile >> "CfgFactionClasses") apply {configName _x};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×