OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: zwobot on 09 Oct 2010, 11:07:11

Title: Retrieve selected value / index from listBox
Post by: zwobot on 09 Oct 2010, 11:07:11
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 (http://forums.bistudio.com/showthread.php?t=57825)):
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
hint format["%1", lbCurSel REQUEST_QUEUE];
hint format["%1", lbSelection REQUEST_QUEUE];

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.
Title: Re: Retrieve selected value / index from listBox
Post by: i0n0s on 09 Oct 2010, 13:51:00
lbCurSel requires an ID or a control. lbSelection requires a control.
From your current code your give them an empty global variable.
Title: Re: Retrieve selected value / index from listBox
Post by: zwobot on 09 Oct 2010, 15:08:13
Sorry, forgot to mention that REQUEST_QUEUE is defined in a .hpp file I include in the relevant script files:
Code: [Select]
#define REQUEST_QUEUE 10002The .rpt file does not moan about undeclared variable REQUEST_QUEUE so I'm sure this is not the problem.
Title: Re: Retrieve selected value / index from listBox
Post by: i0n0s on 09 Oct 2010, 20:00:11
This should work that way. Your dialogue is still open?
And no other control with that idc exists?
Title: Re: Retrieve selected value / index from listBox
Post by: zwobot on 09 Oct 2010, 20:18:28
Yes it is still open. The idc are unique.
The hints display array or scalar
Title: Re: Retrieve selected value / index from listBox
Post by: i0n0s on 09 Oct 2010, 20:31:34
Have you tried
hint format["%1", lbCurSel 10002];
once?
lbSelection won't work since it require a control and not an IDC.
Title: Re: Retrieve selected value / index from listBox
Post by: zwobot on 09 Oct 2010, 20:38:35
Yes, I've tried both IDCs and controls for lbCurSel and lbSelection. Either they don't work at all and dump stuff about what the commands expect into the .rpt or the hint displays array or scalar.

I get the controls like this:
Code: [Select]
disableSerialization;
_dialog = findDisplay 10001; // or with the global variable defined in the header file
_dialog displayCtrl 10002; // or with the global variable defined in the header file

I guess there is some tiny stupid typo error or something like that but I'm blind for it.

Edit: I think it did not work because I used the placeholder for the IDC in " " of a buttonSetAction command. When I'm using the IDC instead of the placeholder now it seems to work. I had to exchange the curled braces { } in the buttonSetAction command with the " " because the command did not work with the braces. Is this the case?

Edit: I sorted it out by formatting the strings with format command.
Thanks for your help i0n0s  :)