zwobot 17 Posted October 9, 2010 Hi, I'm trying to retrieve the index of the selected value of a listBox. The problem is that lbCurSel returns a scalar value and lbSelection returns a value array. Shouldn't both of them return an integer, e. g. 0 if the very first element of the listBox is selected? The listBox is defined like this (using Dr_Eyeball's dialog framework): class RscLB_LIST { // type = defined in derived class idc = -1; style = ST_LEFT; x = 0.1; y = 0.1; w = 0.2; h = Dlg_CONTROLHGT; sizeEx = Dlg_TEXTHGT; rowHeight = Dlg_TEXTHGT; color[] = {Dlg_Color_White,1}; colorText[] = {Dlg_ColorScheme_WindowText,1}; colorBackground[] = {Dlg_ColorScheme_WindowBackground, 1}; // always clear? colorSelect[] = {Dlg_ColorScheme_WindowText,1}; colorSelect2[] = {Dlg_ColorScheme_WindowText,1}; colorScrollbar[] = {Dlg_Color_White,1}; colorSelectBackground[] = {Dlg_ColorScheme_3DControlBackground,1}; colorSelectBackground2[] = {Dlg_ColorScheme_HighlightBackground,1}; font = FontM; soundSelect[] = {"\ca\ui\data\sound\mouse3", 0.2, 1}; soundExpand[] = {"\ca\ui\data\sound\mouse2", 0.2, 1}; soundCollapse[] = {"\ca\ui\data\sound\mouse1", 0.2, 1}; autoScrollSpeed = -1; autoScrollDelay = 5; autoScrollRewind = 0; maxHistoryDelay = 1.0; class ScrollBar { color[] = {1, 1, 1, 0.6}; colorActive[] = {1, 1, 1, 1}; colorDisabled[] = {1, 1, 1, 0.3}; thumb = "\ca\ui\data\igui_scrollbar_thumb_ca.paa"; arrowFull = "\ca\ui\data\igui_arrow_top_active_ca.paa"; arrowEmpty = "\ca\ui\data\igui_arrow_top_ca.paa"; border = "\ca\ui\data\igui_border_scroll_ca.paa"; }; }; class RscListBox: RscLB_LIST { ***type = CT_LISTBOX; ***onLBSelChanged = ""; ***onLBDblClick = ""; }; class REQUEST_QUEUE_DIALOG { movingEnable = 1;//--- The dialog window can be moved. idd = 10001; //onLoad = "ExecVM 'test.sqf'"; //--- Script loaded upon creation. class controls { class REQUEST_QUEUE : RscListBox { idc = 10002; x = 0.21375; y = 0.25889; w = 0.475; h = 0.3; }; }; I add items to the listBox like this: for [{_i=0},{_i < count request_queue_list},{_i=_i+1}] do { lbAdd [REQUEST_QUEUE, format[localize "STR_request_queue_entry", (request_queue_list select _i) select 0, (request_queue_list select _i) ***select 1, (request_queue_list select _i) ***select 2, (request_queue_list select _i) ***select 3,(request_queue_list select _i) ***select 4]] }; request_queue_list is an array and I'm adding it's content into the listBox as formatted strings obviously. So the entries of the listBox contains the elements of the request_queue_list array in the same order but in string format. I use lbCurSel or lbSelection like this: hint format["%1", lbCurSel REQUEST_QUEUE]; hint format["%1", lbSelection REQUEST_QUEUE]; REQUEST_QUEUE is defined in a .hpp file I include in the relevant script files: #define REQUEST_QUEUE 10002 Can you help me to get the selected index of the listBox so I can retrieve the corresponding elements from the request_queue_list array? I'm not very experienced in dialog scripting and would appreciate any best practices you want to share because I'm not sure that the way I'm trying to work with the listBox (adding and retrieving items) is efficient. Share this post Link to post Share on other sites
Evil_Echo 11 Posted October 9, 2010 I never used lbSelection in the ACE ruck system, only lbCurSel in combination with other lb functions. If it helps, one internal function from that code as an example.... _fnc_lbSelectedItem = { private ["_lbIDC", "_contCtrl", "_contIdx"]; _lbIDC = _unit getVariable QUOTE(GVAR(lbIDC)); if(isNil "_lbIDC") then {_lbIDC = AVAILABLE_ITEMS_IDC}; _contCtrl = _display displayctrl _lbIDC; _contIdx = lbCurSel _contCtrl; _itm = _contCtrl lnbData [_contIdx, 1]; _txt = _contCtrl lnbText [_contIdx, 1]; if (_lbIDC == ACE_RUCK_CONTENTS_IDC) then { _txt = _contCtrl lnbText [_contIdx, 0]; _typ = _contCtrl lnbData [_contIdx, 0]; }; ... }; The use of different offsets in getting text or data was due to different layouts of the listbox involved. Share this post Link to post Share on other sites
zwobot 17 Posted October 9, 2010 (edited) Thanks for the answer. The code you provided doesn't help me much without more context. Anyway I think I narrowed the problem down to the way the IDCs are passed to the lbCurSel command by now. I do the following to set the action of a button: buttonSetAction [iDC_GRANT_BUTTON, "[lbCurSel IDC_REQUEST_QUEUE] call grantFireMission;"]; However the IDC_REQUEST_QUEUE placeholder for the IDC apperantly is not resolved properly in the double quotes. I have to use the actual IDC number, then the button action works but I don't want to do this for obvious reasons of code readability and maintenance. On the other hand I can't get curled braces to work at all with the buttonSetAction command: buttonSetAction [iDC_GRANT_BUTTON, {[lbCurSel IDC_REQUEST_QUEUE] call grantFireMission;}]; The above code does not work at all, it doesn't even dump anything into the .rpt file Edit: I sorted it out by formatting the strings with format command. Edited October 9, 2010 by zwobot Share this post Link to post Share on other sites