Jump to content
Sign in to follow this  
wozzsta

isKindOf array? or single string only?

Recommended Posts

Im trying to make an array of the UAVs like this

_uav =  ["B_UGV_01_rcws_F","B_UGV_01_F","B_UAV_01_F","B_UAV_02_F","B_UAV_02_CAS_F"];

and when they spawn i want them to have a crew so i use this. 

if (_vehicle isKindOf  "_uav") then
			{
				createVehicleCrew _vehicle;
					{
						diag_log [_x, faction _x, side _x, side group _x];
					}
				forEach crew _vehicle;
			};

but it doesnt work, it only works when i name them by their ID like this. 

if (_vehicle isKindOf  "B_UGV_01_rcws_F") then
			{
				createVehicleCrew _vehicle;
					{
						diag_log [_x, faction _x, side _x, side group _x];
					}
				forEach crew _vehicle;
			};

and i can only have one uav per statement, can anyone help?

 

Cheers

Share this post


Link to post
Share on other sites

isKindOf works too but then you'd normally just specify the parent-class that all those UAVs have in common. (don't know it by heart)

 

something like this:

 

if (_vehicle isKindOf "UAV") {...

 

 

 

Depends on what you want. (all UAVs or a specific list of them)

Share this post


Link to post
Share on other sites

Try this

_uav = ["B_UGV_01_rcws_F","B_UGV_01_F","B_UAV_01_F","B_UAV_02_F","B_UAV_02_CAS_F"];

if (_vehicle isKindOf _uav) then
			{
				createVehicleCrew _vehicle;
					{
						diag_log [_x, faction _x, side _x, side group _x];
					}
				forEach crew _vehicle;
			};

Share this post


Link to post
Share on other sites

Try this


if (_vehicle isKindOf _uav) then

I think that should not work cause _uav is an array of strings and not a single string as requested by isKindOf

I would suggest:

 

 
if (typeOf _vehicle in _uav) then

Share this post


Link to post
Share on other sites

I think that should not work cause _uav is an array of strings and not a single string as requested by isKindOf

 

 

Sorry my fault

if ((typeOf _vehicle) in _uav) then {

Share this post


Link to post
Share on other sites

hey guys, 

 

Thanks for all the suggestions, i went with 

if (typeOf _vehicle in _uav) then

And it seems to work perfectly, 

 

Cheers :)

  • Like 1

Share this post


Link to post
Share on other sites

Could also do this:
 

_uav = ["B_UGV_01_rcws_F","B_UGV_01_F","B_UAV_01_F","B_UAV_02_F","B_UAV_02_CAS_F"];
{ 
    if (_vehicle isKindOf _x) then
            {
} forEach _uav;
                createVehicleCrew _vehicle;
                    {
                        /* Doing below will make debugging easier, always name your debug data it will make it easier to find bugs.
                           omission of key information from your debug output can come back to but you in the bum big time */ 
                        diag_log format ["Vehicle Name: %1 \n Vehicle Faction name: %2 \n Vehicle: Side %3 \n Vehicle Group Side: %4",_x,(faction _x),(side _x),(side group _x)]; 
                    }
                forEach crew _vehicle;
            };

Share this post


Link to post
Share on other sites

No, you couldn't, that's a script error.

if ({_vehicle isKindOf _x} count _uav > 0) then
...

...would work.

 

But as others have suggested I'd strongly recommend using isKindOf instead.

Share this post


Link to post
Share on other sites

No, you couldn't, that's a script error.

if ({_vehicle isKindOf _x} count _uav > 0) then
...

...would work.

 

But as others have suggested I'd strongly recommend using isKindOf instead.

 

 

What are the advantages of iskindof, over typeof? :)

Share this post


Link to post
Share on other sites

What are the advantages of iskindof, over typeof? :)

You could just measure it to decide it.

Kindly tell us what is faster,please

 

_typo_sum = 0;

for "_i" from 1 to 1000 do
{
 _typo_start = diag_tickTime;

 if ((typeOf _vehicle) in _uav) then 
 { /*do nothing cuz we measure the time of the condition*/ };

 _typo_time = diag_tickTime - _typo_start;
 _typo_sum = _typo_sum + typo_time;
};

 systemchat format ["typo time: %1 ms", (_typo_sum / 1000)];

_kindo_sum = 0;

for "_i" from 1 to 1000 do
{
 _kindo_start = diag_tickTime;

 {
  if (_vehicle isKindOf _x) then 
  { /*do nothing cuz we measure the time of the condition*/ };
 } forEach _uav;

 _kindo_time = diag_tickTime - _kindo_start;
 _kindo_sum = _kindo_sum + kindo_time;
};

 systemchat format ["kindo time: %1 ms", (_kindo_sum / 1000)];
Edited by sarogahtyp

Share this post


Link to post
Share on other sites

You could just measure it to decide it.

 

Not really, you can't compare 2 commands that do totally different things.

It just comes down to what you want to do.

 

 

isTypeOf (combined with an Array) is better when you only want to allow a specific selection of classes.

 

isKindOf is ideal if you want to limit to everything in a specific sub-category (all UAVs for example).

Share this post


Link to post
Share on other sites

Not really, you can't compare 2 commands that do totally different things.

It just comes down to what you want to do.

isTypeOf (combined with an Array) is better when you only want to allow a specific selection of classes.

isKindOf is ideal if you want to limit to everything in a specific sub-category (all UAVs for example).

we have a given example here with a specific class name string which should be compared. i cant see a difference between line 7 and 23 0f my code if _uav contains an array of class name strings. or is there a subtype of that class names?

point that out please.

Share this post


Link to post
Share on other sites

_unit isTypeOf "classname"

> only returns true if _unit is exactly the same class

 

_unit isKindOf "classname"

> returns true if _unit is of the same class or of any subclass that is derived from "classname"

 

using isKindOf as 1:1 replacement for isTypeOf doesn't make sense and can be an Issue if you DONT want it to return true for subclasses.

 

 

 

isTypeOf is the right tool if you have a specific list of classnames that you want to allow

 

isKindOf is the right tool if you want to allow all UAVs with no exceptions, as you only need to do a single check against the base-class which all UAVs have in common.

 

 

 

 

like I said earlier:

Depends on what you want. (all UAVs or a specific list of them)

Share this post


Link to post
Share on other sites

Thanks guys, appreciate the detailed explanations.

 

:)  

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  

×