Jump to content

Sign in to follow this  
x3kj

config value to script variable

Recommended Posts

Hi. what would i have to write if i wanted to read parameters from a config of an object within a subclass?

I've tried to learn anything from the wiki but the descriptions for the config commands are confusing to me.

Only thing (i think) i got is how to get an objects class name, via

_configclassname = configName _object; Is that correct?

Example config:

class Car_F;
class mycar:Car_F {
class Wheels {
	class RandomClassNameABC { myVariable = 5;}		
	class RandomClassName123 { myVariable = 0;}	
};
};

What i would like to do is take a specific object within a game, get the config and find all the classes within the defined class Wheel, and get the value of _myVariable from every class within class Wheel, and store them in an array for example.

Thanks for the help.

Share this post


Link to post
Share on other sites

This example is for classes that are within description.ext, but you only have to modify 1 line to make it work with any config

_wheelVariables = [];
_config = missionConfigFile >> "mycar" >> "Wheels";
_wheels = _config call BIS_fnc_getCfgSubClasses;
{
_wheelVariables pushBack (getNumber (_x >> "myVariable"));
}forEach _wheels;

Share this post


Link to post
Share on other sites

Ok thanks.

I assume for considering all configs ingame for a selected object it would be

_configClass = configName _myobject;

_config = ConfigFile >> _configClass>> "Wheels"; then?

Or can i just use the name of an object type as string for the class like you did in the example?

What happens if class Wheels does not exist? Is _wheels nil in this case?

Edited by X3KJ

Share this post


Link to post
Share on other sites

Check it with isClass :)

if (isClass (ConfigFile >> "CfgVehicles" >> _configClass>> "Wheels")) then {//you have some wheels};

Share this post


Link to post
Share on other sites
  Quote
I assume for considering all configs ingame for a selected object it would be

_configClass = configName _myobject;

_config = ConfigFile >> _configClass>> "Wheels"; then?

Use typeOf _object.

myVariables = [];

_object = createVehicle [ "B_MRAP_01_F", screenToWorld [ 0.5, 0.5 ], [], 0, "CAN_COLLIDE" ];
_wheels = ( configFile >> "CfgVehicles" >> typeOf _object >> "Wheels" );

if ( isClass _wheels ) then {
"
	_property = ( _x >> 'dampingRate' );
	if ( isNumber _property ) then {
		myVariables pushBack ( getNumber _property );
	};	
"configClasses _wheels;
};

hint format [ "%1 has %2 wheels", typeOf _object, count myVariables ];

You dont even need the isClass check with configClasses it will just ignore the command if the class does not exist. e.g

myVariables = [];

_object = createVehicle [ "B_Boat_Armed_01_minigun_F", screenToWorld [ 0.5, 0.5 ], [], 0, "CAN_COLLIDE" ];

"
_property = ( _x >> 'dampingRate' );
if ( isNumber _property ) then {
	myVariables pushBack ( getNumber _property );
};	
"configClasses ( configFile >> "CfgVehicles" >> typeOf _object >> "Wheels" );

hint format [ "%1 has %2 wheels", typeOf _object, count myVariables ];

And myVariables will just be an empty array.

Edited by Larrow

Share this post


Link to post
Share on other sites

thank you very much

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
Sign in to follow this  

×