Jump to content

Recommended Posts

So I can create a list box and add as many items as I want but when clicked they all do the same damn thing, how can I make it so that each item is assigned to a different variable so I can add multiple features to my server menu, please help asap! I've been trying for days

 

VARIABLE_1 = {
 
systemChat "Feature 1 Working";
};

 

createDialog "RscDisplayChat"; 

_3Dprinter = findDisplay 24 ctrlCreate ["RscListBox", 1337]; 

_3Dprinter ctrlCommit 0; 

_3Dprinter  ctrlSetPosition [0.35,0.1,0.25  (1.33),3.8  (0.2)]; 

_3Dprinter ctrlCommit 0; 

_3Dprinter ctrlShow true; 


_Feature1 = "Feature 1";
_Feature2 = "Feature 2";

 

3Dprinter lbAdd Feature1;
3Dprinter lbAdd Feature2;

 

_3Dprinter ctrlSetEventHandler ["LbDBlClick","call VARIABLE_1;"];

Share this post


Link to post
Share on other sites
12 hours ago, HazJ said:

Is this what you are looking for?

https://community.bistudio.com/wiki/lbAdd

https://community.bistudio.com/wiki/lbSetData


{
	_index = lbAdd [1337, _x];
	lbSetData [1337, _index, _x];
} forEach ["A", "B", "C"];

More information can be found on the Wiki.

 

Sorry for me being stupid, I still don't understand how this can be integrated, can you please add it to my code?

Share this post


Link to post
Share on other sites

Replace the following with what I sent?

_Feature1 = "Feature 1";
_Feature2 = "Feature 2";
3Dprinter lbAdd Feature1;
3Dprinter lbAdd Feature2;

It will do a forEach loop and add the texts A, B and C in the list in that specific order. I don't understand how you can be stuck? Did you even test it? What don't you understand, etc...? Oh and btw, I recommend you use SafeZone for your dialog position as it may not look correct across all screen sizes.

  • Like 1

Share this post


Link to post
Share on other sites
10 minutes ago, 3Dprinter2K17 said:

 

Sorry for me being stupid, I still don't understand how this can be integrated, can you please add it to my code?

Ok so it's working and A, B and C is listed but how do I assign them to a variable, adding items was never the problem

Share this post


Link to post
Share on other sites
Just now, HazJ said:

Replace the following with what I sent?


_Feature1 = "Feature 1";
_Feature2 = "Feature 2";
3Dprinter lbAdd Feature1;
3Dprinter lbAdd Feature2;

It will do a forEach loop and add the texts A, B and C in the list in that specific order. I don't understand how you can be stuck? Did you even test it? What don't you understand, etc...? Oh and btw, I recommend you use SafeZone for your dialog position as it may not look correct across all screen sizes.

oh ok cool, so it's showing the correct items in the box but how can I add them to an eventhandler?

Share this post


Link to post
Share on other sites

What are you trying to do? Do you want them to do something when clicked (the item in the list)? I presume so. Here:

(findDisplay 24) ctrlAddEventHandler ["LBSelChanged", {hintSilent _this;}];

https://community.bistudio.com/wiki/User_Interface_Event_Handlers

Quote

The selection in a listbox is changed. The left mouse button has been released and the new selection is fully made.

Quote

Returns the control and the selected element index.

 

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

What are you trying to do? Do you want them to do something when clicked (the item in the list)? I presume so. Here:


(findDisplay 1337) ctrlAddEventHandler ["LBSelChanged", {hintSilent _this;}];

https://community.bistudio.com/wiki/User_Interface_Event_Handlers

 

 

Basically I want a textbox with multiple options and when you double click on an item it calls the variable I have created for it, I don't know how to make it do that when I click on the listbox item all I can manage to do it make it run the same thing as I cant assign a variable

Share this post


Link to post
Share on other sites

Use LBDblClick instead. Return the variable of what? All your VARIABLE_1 function does is output a systemChat message? Also, as shown already. You can store information in the list items.

https://community.bistudio.com/wiki/lbSetData

https://community.bistudio.com/wiki/lbSetValue

https://community.bistudio.com/wiki/lbData

https://community.bistudio.com/wiki/lbValue

Sorry! I think I made a mistake with the ctrlAddEventHandler... Got confused with displayAddEventHandler.

((findDisplay 24) displayCtrl 1337) ctrlAddEventHandler ["LBDblClick", {hintSilent _this;}];

 

  • Like 1

Share this post


Link to post
Share on other sites
Just now, HazJ said:

Use this LBDblClick instead. Return the variable of what? All your VARIABLE_1 function does is output a system chat message? Also, as shown already. You can store information in the list items.

https://community.bistudio.com/wiki/lbSetData

https://community.bistudio.com/wiki/lbSetValue

https://community.bistudio.com/wiki/lbData

https://community.bistudio.com/wiki/lbValue

 

I have read all these already and don't understand it, please can you fix my code, and yes I know it's for testing. basically I can make the list box, I can add the items, I just cant make it do something different each button I click, they all do the same thing as they're all under _3Dprinter so this code _3Dprinter ctrlSetEventHandler ["LbDBlClick","call TEST_VARIABLE_NEW;"]; literally makes the same variable get called for each button you press, I want to be able to set for example A when pressed does variable 3D_A and B does 3D_B that way I can add features to each unique button but I don't know how to do that..

Share this post


Link to post
Share on other sites

Sigh. Add me on Steam so I can help you understand a lot easier. Please also take note of my correction for the mistake I made earlier. For anyone else who wants to know, I will post the rest once resolved.

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, HazJ said:

Sigh. Add me on Steam so I can help you understand a lot easier. Please also take note of my correction for the mistake I made earlier. For anyone else who wants to know, I will post the rest once resolved.

I'll PM you my link

Share this post


Link to post
Share on other sites

As requested...

RscListBox.sqf:

disableSerialization;

3D_One = "1";
3D_Two = "2";
3D_Three = "3";

createDialog "RscDisplayChat";

_dialog = (findDisplay 24) ctrlCreate ["RscListBox", 1337];
// As I said earlier... I recommend you use SafeZone... These values are completely different to yours. I just made a fresh one quickly instead.
_dialog ctrlSetPosition [(0.3 * safezoneW + safezoneX), (0.24 * safezoneH + safezoneY), (0.4 * safezoneW), (0.52 * safezoneH)];
_dialog ctrlCommit 0;

{
	private _data = _x;
	_index = lbAdd [1337, (_data select 0)];
	lbSetData [1337, _index, (_data select 1)];
} forEach
[
	["One", "3D_One"],
	["Two", "3D_Two"],
	["Three", "3D_Three"]
];

((findDisplay 24) displayCtrl 1337) ctrlAddEventHandler ["LBDblClick",
{
	private _variableSelected = lbData [1337, (_this select 1)];
	hintSilent format ["Variable selected: %1", (str _variableSelected)];
}];

Example mission:

https://1drv.ms/u/s!ArYSs9w5RSIDhCsiPH9FZKhyjioV

  • Like 1

Share this post


Link to post
Share on other sites

So im not having any luck with call compile, I assumed I would be replacing this systemchat format ["Variable selected: %1", (str _variableSelected)]; but regardless I can't call anything still hmmm

Share this post


Link to post
Share on other sites

Here you go.

disableSerialization;

x3D_One = true;
x3D_Two = false;
x3D_Three = objNull;

createDialog "RscDisplayChat";

_dialog = (findDisplay 24) ctrlCreate ["RscListBox", 1337];
// As I said earlier... I recommend you use SafeZone... These values are completely different to yours. I just made a fresh one quickly instead.
_dialog ctrlSetPosition [(0.3 * safezoneW + safezoneX), (0.24 * safezoneH + safezoneY), (0.4 * safezoneW), (0.52 * safezoneH)];
_dialog ctrlCommit 0;

{
	private _data = _x;
	_index = lbAdd [1337, (_data select 0)];
	lbSetData [1337, _index, (_data select 1)];
} forEach
[
	["One", "x3D_One"],
	["Two", "x3D_Two"],
	["Three", "x3D_Three"]
];

((findDisplay 24) displayCtrl 1337) ctrlAddEventHandler ["LBDblClick",
{
	private _variableSelected = lbData [1337, (_this select 1)];
	private _variable = compile _variableSelected;
	hintSilent format ["Variable selected: %1\nVariable returns: %2", (str _variableSelected), (call _variable)];
}];

Don't start variables with a number! My bad (kind of). That is what you told me your variables were at the time, was too focussed on writing the code.

Share this post


Link to post
Share on other sites

Already tested! Works fine! I have just updated the example mission too. Same link!

Share this post


Link to post
Share on other sites
1 minute ago, HazJ said:

Already tested! Works fine! I have just updated the example mission too. Same link!

 

I just tested it replacing x3D_One = true with x3D_One = { systemChat "finally working"; };

just to see if it now works and all it's doing is displaying it in a hint format as you made it do. hmmmmm

I see the compile you added but it doesn't seem to be working for me?

Share this post


Link to post
Share on other sites
1 minute ago, HazJ said:

 

 

 So yes I see that it's hinting it but it's not actually running the code for example if you replace x3D_One = true;

with

x3D_One = { systemChat "test"; };

 

it only hints the whole code and doesn't run it

Share this post


Link to post
Share on other sites
Just now, 3Dprinter2K17 said:

 So yes I see that it's hinting it but it's not actually running the code for example if you replace x3D_One = true;

with

x3D_One = { systemChat "test"; };

 

it only hints the whole code and doesn't run it

I'm looking for it to actually call the variable only and not just display what's inside of it

Share this post


Link to post
Share on other sites

Your problem is right there:

x3D_One = { systemChat "finally working"; };
disableSerialization;

x3D_One = "One";
x3D_Two = "Two";
x3D_Three = "Three";

createDialog "RscDisplayChat";

_dialog = (findDisplay 24) ctrlCreate ["RscListBox", 1337];
// As I said earlier... I recommend you use SafeZone... These values are completely different to yours. I just made a fresh one quickly instead.
_dialog ctrlSetPosition [(0.3 * safezoneW + safezoneX), (0.24 * safezoneH + safezoneY), (0.4 * safezoneW), (0.52 * safezoneH)];
_dialog ctrlCommit 0;

{
	private _data = _x;
	_index = lbAdd [1337, (_data select 0)];
	lbSetData [1337, _index, (_data select 1)];
} forEach
[
	["One", "x3D_One"],
	["Two", "x3D_Two"],
	["Three", "x3D_Three"]
];

((findDisplay 24) displayCtrl 1337) ctrlAddEventHandler ["LBDblClick",
{
	private _variableSelected = lbData [1337, (_this select 1)];
	private _variable = compile _variableSelected;
	hintSilent format ["Variable selected: %1\nVariable returns: %2", (str _variableSelected), (call _variable)];
	systemChat (call _variable);
}];

I don't think you need call, etc... Maybe just the STRING. Depends on if you are only using this for systemChat, etc... Anyway. I'm taking a break for now. My brain is hurting lo!! :)

 

PS: Example mission NOT updated.

Share this post


Link to post
Share on other sites
2 minutes ago, HazJ said:

Your problem is right there:


x3D_One = { systemChat "finally working"; };

disableSerialization;

x3D_One = "One";
x3D_Two = "Two";
x3D_Three = "Three";

createDialog "RscDisplayChat";

_dialog = (findDisplay 24) ctrlCreate ["RscListBox", 1337];
// As I said earlier... I recommend you use SafeZone... These values are completely different to yours. I just made a fresh one quickly instead.
_dialog ctrlSetPosition [(0.3 * safezoneW + safezoneX), (0.24 * safezoneH + safezoneY), (0.4 * safezoneW), (0.52 * safezoneH)];
_dialog ctrlCommit 0;

{
	private _data = _x;
	_index = lbAdd [1337, (_data select 0)];
	lbSetData [1337, _index, (_data select 1)];
} forEach
[
	["One", "x3D_One"],
	["Two", "x3D_Two"],
	["Three", "x3D_Three"]
];

((findDisplay 24) displayCtrl 1337) ctrlAddEventHandler ["LBDblClick",
{
	private _variableSelected = lbData [1337, (_this select 1)];
	private _variable = compile _variableSelected;
	hintSilent format ["Variable selected: %1\nVariable returns: %2", (str _variableSelected), (call _variable)];
	systemChat (call _variable);
}];

I don't think you need call, etc... Maybe just the STRING. Depends on if you are only using this for systemChat, etc... Anyway. I'm taking a break for now. My brain is hurting lo!! :)

 

PS: Example mission NOT updated.

 

I'm not looking to just have a systemchat.... I was just putting that inside of it for an example.

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

×