Jump to content
CryForce-f630d58d86399ab9

Arma 3 Dialog - Displaying an image on Listbox selection

Recommended Posts

so I'm relatively new to Dialog Scripts in Arma 3 but what I'm trying to do is if the player selects an item in the Listbox. The item will then display a picture on the right and side depending on what item I select in the list box

1cd8dbbf3ba08b5d695a9da5041ec375.png

 

I've made sure my images can be linked to the display as entering them into the ctrlSetText works, but I can't figure out how I can go about making it display the image depending on what item I have selected.
At first, I thought of just using if statements but I saw problems with it and an if statement for each item seems a bit of a workaround. so I decided to use Switch {} do and a case for each image as the _index gets a number that I assumed would work if I placed them into different cases like this.

switch {_itemNumber} do // gets value
	{
		case (0): {ctrlSetText [1200, "images\1.paa"]}; // displays first item image 
		case (1): {ctrlSetText [1200, "images\2.paa"]}; // displays second item image 
		default {ctrlSetText [1200, ""]};	// if no item is selected displays nothing
	};

but I couldn't get it to display even though when I print it using the HINT command it prints the item selected via a number
here is the full script: recipes.sqf

disableserialization;

_recipeArray = ["Food Materials", "Raw Materials"]; // array of items in list
_ctrl = (findDisplay 3663) displayCtrl 1500; // finds dialog

{
	_ctrl lbAdd _x;
} forEach _recipeArray; // adds the _recipe array to list box


while {!isNull (findDisplay 3663);} do // only loops when the display is open
{
	sleep 1;
	_index = lbCurSel 1500; // gets _index value from selected item
	hint str (_index); // prints selection value for testing

	switch {_index} do // gets the _index value
	{
		case (0): {ctrlSetText [1200, "images\1.paa"]}; // displays first item image 
		case (1): {ctrlSetText [1200, "images\2.paa"]}; // displays second item image 
		default {ctrlSetText [1200, ""]};	// if no item is selected displays nothing
	};
};

if anyone could help I would be grateful.

Share this post


Link to post
Share on other sites

UI eventhandlers are your friend!

 

disableserialization;
//--- Using idcs to indentify your controls is fine when using the createDialog command but using displayCtrl is safer and in some cases the only option
_display = findDisplay 3663;// Can also be replaced with the onLoad eventhandler as the first parameter is the display
_listbox = _display displayCtrl 1500;

//--- Add items to the listbox
_recipeArray = ["Food Materials", "Raw Materials"]; // array of items in list
{
	_listbox lbAdd _x;
} forEach _recipeArray;

//--- Add an eventhandler to the listbox that executes code when the user selects an entry
_listbox ctrlAddEventHandler ["LBSelChanged",
{
  	//--- This is a completely independent script so any variables from the main scope are not avaiable here
	params ["_listbox","_index"];// Arguments that were passed from the event
	_ctrlPicture = ctrlParent _listbox displayCtrl 1200;// ctrlParent returns the display (can also be replaced with finddisplay IDD)
	_picture = ["images\1.paa","images\2.paa"] param [_index, ""]; // Same as select but prevents loading of a file that doesn't exist
	_ctrlPicture ctrlSetText _picture;
}];

 

Edited by 7erra
code didnt work

Share this post


Link to post
Share on other sites
23 minutes ago, 7erra said:

UI eventhandlers are your friend!

 


disableserialization;
//--- Using idcs to indentify your controls is fine when using the createDialog command but using displayCtrl is safer and in some cases the only option
_display = findDisplay 3663;// Can also be replaced with the onLoad eventhandler as the first parameter is the display
_listbox = _display displayCtrl 1500;

//--- Add items to the listbox
_recipeArray = ["Food Materials", "Raw Materials"]; // array of items in list
{
	_listbox lbAdd _x;
} forEach _recipeArray;

//--- Add an eventhandler to the listbox that executes code when the user selects an entry
_listbox ctrlAddEventHandler ["LBSelChanged",
{
  	//--- This is a completely independent script so any variables from the main scope are not avaiable here
	params ["_listbox","_index"];// Arguments that were passed from the event
	_ctrlPicture = ctrlParent _listbox displayCtrl 1200;// ctrlParent returns the display (can also be replaced with finddisplay IDD)
	_picture = ["images\1.paa","images\2.paa"] param [_index, ""]; // Same as select but prevents loading of a file that doesn't exist
	_ctrlPicture ctrlSetText _picture;
}];

 


Hey 7erra, thanks for the help, it looks like its working however I'm getting an Invalid number in expression error but, the code does work and changes pictures how its meant to which is great.
721374fa9aab8ea13dc0aa549ec914a7.png

Share this post


Link to post
Share on other sites

Errrr...

Spot the difference:

b8LWbiz.png

That's right: One works the other doesn't. (???)

Here is the working one:

disableserialization;
//--- Using idcs to indentify your controls is fine when using the createDialog command but using displayCtrl is safer and in some cases the only option
_display = findDisplay 3663;// Can also be replaced with the onLoad eventhandler as the first parameter is the display
_listbox = _display displayCtrl 1500;

//--- Add items to the listbox
_recipeArray = ["Food Materials", "Raw Materials"]; // array of items in list
{
	_listbox lbAdd _x;
} forEach _recipeArray;

//--- Add an eventhandler to the listbox that executes code when the user selects an entry
_listbox ctrladdeventhandler ["LBSelChanged",{
	params ["_listbox","_index"];
	_ctrlPicture = (ctrlParent _listbox) displayCtrl 1200;
	_picture = ["images\1.paa","images\2.paa"] param [_index, ""];
	_ctrlPicture ctrlSetText _picture;
}];
  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, CryForce-f630d58d86399ab9 said:

I think it may have been an invisible character that I didn't notice when I copied it over mine.

 

THIS Bug will go forever right ?!

Can a Moderator check about it ?

Thanks !

 

PS : if this is already checked somehow , please reply in order to know .

Thanks !

Spoiler

721374fa9aab8ea13dc0aa549ec914a7.png

 

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

×