Page MenuHomeFeedback Tracker

[Feature Request] New scripting command for returning the first element of array1 in array2: findIn/findAny
Assigned, NormalPublic

Description

Is it possible to add a command that finds if an element from array1 is in array2? findIf is too slow for my use. arrayIntersect is better but a waste of performance (also, given the fact that it runs unscheduled, it can result in an FPS drop if you're working with large arrays)
So in short, what I want is a command that combines both of these commands and returns an index similar to find.
something like:

array1 findAny array2

which gives the index of the first element from array1 that's in array2. Currently, one would have to use:

array1 find (array2 arrayIntersect array1 select 0)

or

array1 findIf {_x in array2}

both are not optimal.
example:

[1,2,3] findAny [5,3,2]

returns: 1 (i.e. the index of the element 2 from the [1,2,3] array)

Details

Severity
Feature
Resolution
Open
Reproducibility
N/A
Operating System
Windows 7
Category
Feature Request

Event Timeline

Leopard20 changed Severity from None to Feature.
Leopard20 changed Category from General to Feature Request.
Leopard20 updated the task description. (Show Details)Oct 11 2020, 5:51 PM
Leopard20 renamed this task from [Feature Request] New scripting command for returning the first element of array1 in array2: findIn to [Feature Request] New scripting command for returning the first element of array1 in array2: findIn/findAny.Thu, Jan 7, 2:03 PM
Leopard20 added a comment.EditedThu, Jan 7, 2:18 PM

this command would have several applications.

for example, it can be used to find if a unit has certain magazines/items:

_magazines = ["RPG7_F", "STANAG_556_F", ....];
items _unit findAny _magazines != -1;
//or
magazines _unit findAny _magazines != -1;


//current method:
count _items != count (_items - _magazines)
Leopard20 updated the task description. (Show Details)Thu, Jan 7, 6:35 PM
Leopard20 updated the task description. (Show Details)Thu, Jan 7, 6:40 PM
h- added a subscriber: h-.Thu, Jan 7, 6:43 PM
dedmen claimed this task.Thu, Jan 7, 6:57 PM
dedmen changed the task status from New to Assigned.
dedmen set Ref Ticket to AIII-53701.
heyoxe added a subscriber: heyoxe.Thu, Jan 7, 8:54 PM
Leopard20 updated the task description. (Show Details)Thu, Jan 7, 10:13 PM