Jump to content
Sign in to follow this  
solrac42

Searching Arrays

Recommended Posts

I have come across a problem in ArmA 1 searching arrays.

The 'find' command does not always find the element in the array.

For example, I have an array called targetLst containing [GUER 1-1-B:1,GUER 1-1-B:2,GUER 1-1-B:3,GUER 1-1-A:1,GUER 1-1-A:2] I have a variable called _nearest containing 1-1-A:1 and I use the code ... _targetId = targetLst find _nearest, the result is always -1 for targetId when it should be 3 for the element in the array.

I also tried a 'for' loop to search for the element in the array and it also failed to find the element, the code is ....

for "_x" from 0 to ((count targetLst)-1) do {

_object = targetLst select _x;

if (_object == _nearest) then {_targetId = _x};

};

Has anyone found this problem with finding elements in an array in ArmA 1.

Share this post


Link to post
Share on other sites

I suspect your targetLst is in fact an array of strings, so what happens with :

["GUER 1-1-B:1","GUER 1-1-B:2","GUER 1-1-B:3","GUER 1-1-A:1","GUER 1-1-A:2"] ?

(And of course _nearest containing "1-1-A:1").

Edited by ProfTournesol

Share this post


Link to post
Share on other sites

Hi ProfTournesol,

My _targetLst array is a list of units collected from a trigger with "any" as the type to look for so that the list will be a complete list of any units on the map.

The code I specified works fine for any soldier unit but does not work for units in vehicles, and yet I know the unit is in the array because I printed the contents of the variables _object, _nearest and the _targetLst array on the screen and I can see visually that they match, but still the 'find' command will not find it in the array, so I think it must be a bug is BIS code.

Share this post


Link to post
Share on other sites

Ok, so if i understand correctly :

- "find" works with single units on the map

- it doesn't work with units in vehicles ?

That sounds logical to me :

If i put the same trigger as yours on the map and if a soldier is on the map, it appears in the trigger's list. Once the soldier boards a vehicle, the soldier isn't in the triggers list anymore. So the find command can't work. In fact, vehicle "counts" (and are detected) as one unit only, whatever units are aboard them.

Is it what you're experiencing ?

Share this post


Link to post
Share on other sites

I can see your point but the fact is that the units description such as GUER 1-1-A:1 in still in the array but the the 'find' command does not see it.

If we forget about the unit being in a vehicle for the moment and just look at the logic of having the data in the array, then surley the 'find' command should parse the array and give its location index in the array, which in this case would be 3, can you see my point ?, this should be true regardless of units or vehicles.

Share this post


Link to post
Share on other sites

Your point is hardly visible. I'm not sure whether it's about unit!=vehicle unit or different data types.

Best if you send example mission with your code.

Share this post


Link to post
Share on other sites

Well, i've made some tests (in ArmA2 cause ArmA isn't installed anymore for me, but i don't think it should be any different on that matter) and i haven't got any trouble to retrieve an array element position inside this array through the find command.

So we know how you constituted the targetLst array through a trigger, but how was created the _nearest variable ?

Share this post


Link to post
Share on other sites

The _nearest variable was created by the following code :

_nearest = objNull;

_objects = nearestObjects [[_xpos, _ypos, 0], ["All"], 10];

_nearest = _objects select 0;

if (not isNull _nearest) then {_targetId = _targetLst find _nearest};

Edited by solrac42

Share this post


Link to post
Share on other sites

Bah! It's nothing new and it's not about the find command.

Next time try to write a better description of the problem.

Link to test mission

Unit is not equal to Unit in vehicle. Such mounted unit is not caught by trigger, only the vehicle itself.

If you want to make this work then you'll have to build list of units differently (more than trigger).

Edited by Faguss

Share this post


Link to post
Share on other sites

Yep, you're right Faguss, I have used a different method and it works, thanks for the advice though.

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  

×