• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Trigger] Reference the value of an array index

Status
Not open for further replies.
Level 3
Joined
Mar 18, 2020
Messages
20
Is it possible to retrieve the index of an array?

For example, if you have a Unit Group Array of 100 Unit Groups, and I select a unit on the map, is it possible to call a function that would return the index of the unit group that is selected?

I.e., selecting a unit from UnitGroupArray[40] would send a Game message to all players "40". Specifically I'm not looking for workarounds (like setting the custom value or some other integer property of units in the unit group to the array index) since I'd hope a solution could be applicable to any array of any handle.

Thanks
 
I'm not looking for workarounds (like setting the custom value or some other integer property of units in the unit group to the array index)
A unit can be stored inside many unit groups. A unit can stored inside many unit arrays.
It's not possible there comes a magix index out of nothing, just because it's needed in a case. The index information needs to be attached to the unit with code, and then it can be retrieved.
 
Level 14
Joined
Feb 7, 2020
Messages
387
Did you mean you want to find where a value exists, then raise where it is indexed at? Such as returning where a group variable or particular unit in the group table is stored?

If so, I had to do something utilizing this functionality so I made a helper function for it:

Lua:
-- @t = table to search
-- @v = value to search for, returns index of that value where it exists in @t
function GetTableIndexByValue(t,v)
    for index, value in pairs(t) do
        if value == v then
            return index
        end
    end
    return nil
end
This may or may not help you. I was a bit confused by the exact ask.
 
Status
Not open for further replies.
Top