noilliz 38 Posted April 27, 2017 I'm currently working on a vehicle selector script, but I seem to have trouble putting the array in my list box The code below will shot 1 till 4 in the listbox. _list = ["1", "2", "3", "4"]; _ctrl1 = (findDisplay 7720) displayCtrl 1500; { _ctrl1 lbAdd _x; } forEach _List); However, that's not what I want, I only want 1 and 3 to show while still being able to expand the array for as long as I wish. So i thought why not make it a dimensional array and select 0 of each array but how? How do i get _list = [["1", "2"], ["3", "4"]]; to output 1 and 3. I have been trying a lot but I can't seem to get it to work properly, A quick google search gave me no results. If it's there excuse me for not finding it. Cheers, Joey Share this post Link to post Share on other sites
xjoker_ 25 Posted April 27, 2017 _list = [["1", "2"], ["3", "4"]]; _ctrl1 = (findDisplay 7720) displayCtrl 1500; { _ctrl1 lbAdd (_x select 0); } foreach _list; 1 Share this post Link to post Share on other sites
Grumpy Old Man 3545 Posted April 27, 2017 Pretty easy once you think about it a bit. A multidimensional array is nothing more than an array nested inside an array. When '_list' is ["1","2","3"] then _x in the forEach loop refers to a string. When '_list' is [["1", "2"], ["3", "4"]] then _x in the forEach loop refers to an array of strings. How do you get a value from an array? By using 'select'. So you'll do this: _list = [["1", "2"], ["3", "4"]]; _ctrl1 = (findDisplay 7720) displayCtrl 1500; { _ctrl1 lbAdd (_x select 0); } forEach _List); Cheers 1 Share this post Link to post Share on other sites
noilliz 38 Posted April 27, 2017 1 hour ago, xjoker_ said: _list = [["1", "2"], ["3", "4"]]; _ctrl1 = (findDisplay 7720) displayCtrl 1500; { _ctrl1 lbAdd (_x select 0); } foreach _list; 59 minutes ago, Grumpy Old Man said: Pretty easy once you think about it a bit. A multidimensional array is nothing more than an array nested inside an array. When '_list' is ["1","2","3"] then _x in the forEach loop refers to a string. When '_list' is [["1", "2"], ["3", "4"]] then _x in the forEach loop refers to an array of strings. How do you get a value from an array? By using 'select'. So you'll do this: _list = [["1", "2"], ["3", "4"]]; _ctrl1 = (findDisplay 7720) displayCtrl 1500; { _ctrl1 lbAdd (_x select 0); } forEach _List); Cheers That's what I thought, tried it and it did not work, but since you guys suggested it I tried again. And now it does work, well thanks a lot! I must have made a mistake somewhere down the line. Share this post Link to post Share on other sites