ozdeadmeat 12 Posted December 27, 2017 I am suffering from the dumb this morning. I want to find the index of an array of objects OBJECT_ARRAY = [Vehicle1, Vehicle2, Vehicle3] ; OBJECT_NAME = ["Chocolate", "Vanilla", "Chai freaking Latte"]; E.G. I have multiple arrays that are consistently indexed. So if I find Vehicle3 as index 2 I should be able to get the name by using OBJECT_NAME select _index. I am not sure I am explaining this 100% well it is 3:30am and I have been banging my head against the wall for too long on this. Any help is appreciated. Share this post Link to post Share on other sites
beno_83au 1369 Posted December 27, 2017 Well, OBJECT_NAME select 2 will return "Chai freaking Latte". Is that what you're asking? If that's the case, you can use arrays within an array: _array = [ [Vehicle1,"Chocolate"], [Vehicle2,"Vanilla"], [Vehicle3,"Chai Freaking Latte"] ]; _object = (_array select 2) select 0; //returns Vehicle3 _name = (_array select 2) select 1; //returns "Chai Freaking Latte" Then you can use whatever index you need on _array to select the required vehicle and its array of info. I could be entirely missing your question though. Share this post Link to post Share on other sites
squeeze 22 Posted December 27, 2017 _index got changed to _foreachindex way back, i haven't done much scripting lately but i think _index == _mylocalvarible Share this post Link to post Share on other sites
Lucullus 71 Posted December 27, 2017 one possibility: tag_fnc_findVar = { params ["_obj","_id"]; _objectArray = [ "Vehicle1",["Chocolate",1,2], "Vehicle2",["Vanilla",3,4], "Vehicle3",["Chai freaking Latte",5,6] ] ; _index = _objectArray find _obj; (_objectArray select _index+1) select _id }; _var = ["Vehicle3",1] call tag_fnc_findVar; hint str (_var); // 5 Share this post Link to post Share on other sites
AZCoder 921 Posted December 27, 2017 https://community.bistudio.com/wiki/find Not tested: OBJECT_ARRAY = [Vehicle1, Vehicle2, Vehicle3] ; OBJECT_NAME = ["Chocolate", "Vanilla", "Chai freaking Latte"]; _idx = OBJECT_ARRAY find Vehicle2; systemChat (OBJECT_NAME select _idx); // should return Vanilla 1 Share this post Link to post Share on other sites
Lucullus 71 Posted December 28, 2017 You should handle strings or numbers in an array, not objects. If an object doesn't exist, you will get an undefined variable error. Share this post Link to post Share on other sites
panther42 52 Posted January 4, 2018 No need to re-invent the wheel. If using CBA 3, fnc_hashCreate. Allows for default value. Share this post Link to post Share on other sites
pierremgi 4851 Posted January 5, 2018 19 minutes ago, panther42 said: No need to re-invent the wheel. If using CBA 3, fnc_hashCreate. Allows for default value. No need to depend on CBA or else Share this post Link to post Share on other sites