Jump to content
riten

Dialog listbox > button [Solved]

Recommended Posts

So I need Listbox in dialog to allow player select aircraft. Selection works if I double click on list but I want also a button to select items from list but it doesn't works.

 

My dialog:

...

class ICE_LISTBOX: RscListbox
			{
				idc = 1500;
				x = 0.401563 * safezoneW + safezoneX;
				y = 0.318 * safezoneH + safezoneY;
				w = 0.124687 * safezoneW;
				h = 0.168 * safezoneH;
				onLBSelChanged = systemChat str [_this select 0, (_this select 0) lbText (_this select 1), (_this select 0) lbData (_this select 1)];
				onLBDblClick = ((_this select 0) lbText (_this select 1)) execVM "Aircrafts_class.sqf";
			};
class ICE_SELECT_BTN: RscButton
			{
				idc = 1602;
				text = "select"; //--- ToDo: Localize;
				x = 0.480312 * safezoneW + safezoneX;
				y = 0.5 * safezoneH + safezoneY;
				w = 0.0525 * safezoneW;
				h = 0.028 * safezoneH;
				
				onMouseButtonClick = "this = [_this,(1500 lbText (lbCurSel 1500))] execVM 'Aircrafts_class.sqf';";
			};

...

listbox.sqf (executed onload):

{lbAdd[1500,_x]} forEach ["A-10 Wipeout","2","Listbox 3","Listbox 4","Buzzard CAS","Buzzard (AA)","Listbox 7","Listbox 8"];

aircrafts_class.sqf:

switch (_this) do {
    case "A-10 Wipeout": {
			if (isnil "samolot") then {respsamolot=0;};
			if (samolot isKindOf "B_Plane_CAS_01_F") then {respsamolot=1;} else {respsamolot=0;};	
			if (respsamolot==0) then {deletevehicle Samolot; sleep 5; Samolot = "B_Plane_CAS_01_F" createVehicle getMarkerPos "serwis"; sleep 0.2; samolot setdir 45; };
            };			
    ...
};

Share this post


Link to post
Share on other sites

buttons have an action attribute:

...
class ICE_SELECT_BTN: RscButton
{
	idc = 1602;
	text = "select"; //--- ToDo: Localize;
	x = 0.480312 * safezoneW + safezoneX;
	y = 0.5 * safezoneH + safezoneY;
	w = 0.0525 * safezoneW;
	h = 0.028 * safezoneH;
	action = "code here;";		
};

Share this post


Link to post
Share on other sites

I know about action attribute, but I'd like to get into aircrafts_class.sqf script case like I said in first post. 

 

I need something like this to work:

onMouseButtonClick = "this = [_this,(1500 lbText (lbCurSel 1500))] execVM 'Aircrafts_class.sqf';";

Share this post


Link to post
Share on other sites

So youre trying to change the information shown on the GUI when you click on the list? or you want to click the list, then click a button to execute what is selected in the list?

Share this post


Link to post
Share on other sites

You're not checking the right data with your switch. Your data structure contained in _this looks like this:

[_this,(1500 lbText (lbCurSel 1500))] or [control_array, "string"]

 

However, if your script you use:

switch (_this) do

Since you pass an array to the script, it will never be equal to a string, thus no cases will be a match and no code runs.

You might try changing your switch to this:

switch (_this select 1) do //this will pass only the second element in the array which is a string

I've never used onMouseButtonClick with a button control (since action exists), but it should work. You will want to add a hint or systemChat to the very beginning of your script to confirm that it is running, it can be removed after you see it.

If you have problems even after adding a hint or systemChat, might just be a good idea to change onMouseButtonClick to action

Share this post


Link to post
Share on other sites

 or you want to click the list, then click a button to execute what is selected in the list?

 

That is exactly what I try to do. 

 

@dreadedentity

 

I'm 90% sure that I've tried to change my switch condition (I'll try once again), but still it didn't work. If switch is a problem then this part shouldn't work (but it works):

class ICE_LISTBOX: RscListbox
{
...
onLBDblClick = ((_this select 0) lbText (_this select 1)) execVM "Aircrafts_class.sqf";
...

so I just need to do similar thing with "select button". 

 

Thanks for replies, hope I'll find solution.

 

------------------------------

 

edit:

 

Looks like this is a problem:

onMouseButtonClick = "this = [_this,(1500 lbText (lbCurSel 1500))] execVM 'Aircrafts_class.sqf';";

debug console says that "1500 #lbText (lbCurSel 1500" need control behind lbText and the control is idc right? so I've changed it to:

action = "this = [_this,[lbText [1500,(lbCurSel 1500)]]] execVM 'Aircrafts_class.sqf'; hint format ['%1',[lbText [1500,(lbCurSel 1500)]]];";

hint says that it returns correct "A-10 Wipeout", but still I always get wrong switch case (default)...

 

-------------------------

 

edit 2

 

Finally... found soulution. There was problem with both action code and switch condition, changed them to:

action = "this = [[lbText [1500,(lbCurSel 1500)]]] execVM 'Aircrafts_class.sqf';"

and condition:

switch ((lbText [1500,(lbCurSel 1500)])) do {...

Now it works how I want it to work, thanks everyone for help.

  • Like 1

Share this post


Link to post
Share on other sites

That was gonna be my solution to it cos I have a small addon that does exactly that, just wasnt sure, good work finding it.

Share this post


Link to post
Share on other sites

Finally... found soulution. There was problem with both action code and switch condition, changed them to:

action = "this = [[lbText [1500,(lbCurSel 1500)]]] execVM 'Aircrafts_class.sqf';"

and condition:

switch ((lbText [1500,(lbCurSel 1500)])) do {...

Now it works how I want it to work, thanks everyone for help.

Glad you got it working. However you already passed this information to the script. This will make it more convoluted. Use hint str _this or systemChat str _this at the beginning of your script to see what the input is. I then recommend changing your switch to some element of _this. It will make maintenance easier

 

Since you changed what you pass to the script, you should be able to just change your switch to:

switch (_this select 0) do {

And it should work the same. Also keep in mind that you don't need to pass an array to the script. Since you just have 1 element, you can simply do

action = "this = (lbText [1500,(lbCurSel 1500)]) execVM 'Aircrafts_class.sqf';"

and instead of using _this select 0, you can simply use _this. Upon further inspection, you are passing an array with one element, which is another array containing one element, which is the listbox text. So you would need to use this switch statement instead to work properly:

switch ((_this select 0) select 0) do {

I recommend changing the "action" to what I suggested and then changing your switch to just switch (_this) do

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×