Jump to content
Sign in to follow this  
Rothwell

getting "hasGunner" value from config file with getNumber

Recommended Posts

Hi, I'm trying to see if a vehicle has a gunner position in my code, but I am getting "0" no matter what...

_hasGun = getNumber (configFile >> "cfgVehicles" >> _ClassName >> "hasGunner");

As I understand, this should be the correct segment of code to get what I want! (I read on a forum that with Arma2, "hasGunner" applies to the turret, and not the vehicle itself, but it didn't go into any more detail... what does this mean?)

I use this code to find the number of cargo spots, and it works perfectly fine...

TCargoSeats = getNumber (configFile >> "cfgVehicles" >> _ClassName >> "transportSoldier");

Share this post


Link to post
Share on other sites

You can also browse it online here:

http://browser.six-projects.net/cfg_vehicles

Just type in hasGunner in the search.

---------- Post added at 11:14 PM ---------- Previous post was at 11:07 PM ----------

Also you might want to use this :

http://community.bistudio.com/wiki/isNumber

First to check if it is defined. Then reach in to the config and grab it out.

Share this post


Link to post
Share on other sites

Thank you both for your help! I figure I might as well post my solution if anyone else has the same question (I know it doesn't handle turrets within turrets yet... but that's a job for another night):

TGunnerSeats = 0;
if(isClass (_ConfigEntry >> "Turrets")) then
{
_turretClass = (_ConfigEntry >> "Turrets");
for [{_i = 0}, {_i < (count _turretClass)}, {_i = _i+1}] do
{
	if( isNumber ((_turretClass select _i) >> "hasGunner") ) then
	{
		TGunnerSeats = TGunnerSeats + 1;
	};
};
};	

edit: ok, I figured I'd just post the code when it's working 100%...

/////////////find gunner & commander positions////////////////////////
if(isClass (_ConfigEntry >> "Turrets")) then
{

//function start////////////////////////////////////////////////////
TurTrav_func = {
private ["_turretClass","_recurse","_i"];
_turretClass = _this select 0;

for [{_i = 0}, {_i < (count _turretClass)}, {_i = _i+1}] do
{
if( isClass (_turretClass select _i) ) then
{
	//see if it has "gunnerName" in it...
	if( isText ( (_turretClass select _i) >> "gunnerName") ) then
	{
		if( getText ( (_turretClass select _i) >> "gunnerName") == "commander") then
		{
			TCommanderSeats = TCommanderSeats + 1;
		}
		else
		{
			TGunnerSeats = TGunnerSeats + 1;
		};
	};
	//explore this class
	_recurse = [(_turretClass select _i)] call TurTrav_func;
};
};
};
//function end//////////////////////////////////////////////////////

TGunnerSeats = 0;
TCommanderSeats = 0;
_tscript = [(_ConfigEntry >> "Turrets")] call TurTrav_func;

};	

Edited by Rothwell

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  

×