Jump to content
Sign in to follow this  
Ranwer135

ctrlAddEventHandler - Need Help!

Recommended Posts

Hey guys,

I got a dialog into a ".pbo" file with items already added as well in it. Now I wanted to be able to add items from a mission file into the dialog with the command "ctrlAddEventHandler".

The problem is that because the command is somehow too slow, my items randomly appear and disappear. (I have 6 "ctrlEventHandlers")

Is there any other code I could try that will be a lot faster in terms of ms? (And, is it possible to set a Variable on a control, and then get the control from a mission?)

Here are 2 ".sqf" files handling dialogs called "Craft Menu" and "Survival Menu":

C_EH.sqf (Handles event handlers for Craft Menu)

While {alive player} do
{


/* Craft Menu */	

if (!isNull (findDisplay 41052)) then
{
	WaitUntil {!isNull (findDisplay 41052)}
	//Adds Event Handlers onto IDD
	C_BtnCraft = ((findDisplay 41052) displayCtrl 1601) ctrlAddEventHandler ["ButtonClick", {_this execVM "Actions\player_craft.sqf"}];
	C_LBItems = ((findDisplay 41052) displayCtrl 1500) ctrlAddEventHandler ["LBSelChanged", {_this execVM "Dialogs\Craft Menu\Select_Slot.sqf"}];
	C_ComboBox = ((findDisplay 41052) displayCtrl 2100) ctrlAddEventHandler ["LBSelChanged", {_this execVM "Dialogs\Craft Menu\Select_Type.sqf"}];
	C_CtoA = ((findDisplay 41052) displayCtrl 1600) ctrlAddEventHandler ["ButtonClick", {_this execVM "init\A_EH.sqf"}];


	//Removes Event Handlers from IDD
	WaitUntil {isNull (findDisplay 41052)};
	((findDisplay 41052) displayCtrl 1601) ctrlRemoveEventHandler ["ButtonClick", C_BtnCraft];
	((findDisplay 41052) displayCtrl 1500) ctrlRemoveEventHandler ["LBSelChanged", C_LBItems];
	((findDisplay 41052) displayCtrl 2100) ctrlRemoveEventHandler ["LBSelChanged", C_ComboBox];
	((findDisplay 41052) displayCtrl 1600) ctrlRemoveEventHandler ["ButtonClick", C_CtoA];
};
};

A_EH.sqf (Handles event handlers for Survival Menu)

While {alive player} do
{


/* Action Menu */


if (!isNull (findDisplay 41050)) then
{
	WaitUntil {!isNull (findDisplay 41050)};
	//Adds Event Handlers onto IDD
	A_ListBox = ((findDisplay 41050) displayCtrl 1500) ctrlAddEventHandler ["LBSelChanged", {_this execVM "Dialogs\Survival Menu\Select_Slot.sqf"}];
	A_ComboBox = ((findDisplay 41050) displayCtrl 2100) ctrlAddEventHandler ["LBSelChanged", {_this execVM "Dialogs\Survival Menu\Select_Type.sqf"}];
	A_BtnUse = ((findDisplay 41050) displayCtrl 1600) ctrlAddEventHandler ["ButtonClick", {_this execVM "Actions\player_use.sqf"}];
	A_BtnEat = ((findDisplay 41050) displayCtrl 1601) ctrlAddEventHandler ["ButtonClick", {_this execVM "Actions\player_eat.sqf"}];
	A_BtnDrink = ((findDisplay 41050) displayCtrl 1602) ctrlAddEventHandler ["ButtonClick", {_this execVM "Actions\player_drink.sqf"}];
	A_AtoC = ((findDisplay 41050) displayCtrl 1604) ctrlAddEventHandler ["ButtonClick", {_this execVM "init\C_EH.sqf"}];


	//Removes Event Handlers from IDD	
	WaitUntil {isNull (findDisplay 41050)};
	((findDisplay 41050) displayCtrl 1500) ctrlRemoveEventHandler ["LBSelChanged", A_ListBox];
	((findDisplay 41050) displayCtrl 2100) ctrlRemoveEventHandler ["LBSelChanged", A_ComboBox];
	((findDisplay 41050) displayCtrl 1600) ctrlRemoveEventHandler ["ButtonClick", A_BtnUse];
	((findDisplay 41050) displayCtrl 1601) ctrlRemoveEventHandler ["ButtonClick", A_BtnEat];
	((findDisplay 41050) displayCtrl 1602) ctrlRemoveEventHandler ["ButtonClick", A_BtnDrink];
	((findDisplay 41050) displayCtrl 1604) ctrlRemoveEventHandler ["ButtonClick", A_AtoC];
};
};

Thanks,

Rawner135

Edited by Ranwer

Share this post


Link to post
Share on other sites

To make things sound clearer,

My dialog and its items are in a ".pbo". But I want to add more items, but from a mission.

The problem is that the ctrlAddEventHandler takes too long for it to detect a control e.g. being clicked .

What I am trying to achieve is to create a mission where users can add their own stuff into the dialog without having to go into my ".pbo" file.

Share this post


Link to post
Share on other sites

I'm not really sure if this is faster, but it will clear up a lot of space in your project. Did you know you can tell the engine to add a control event handler during it's creation? Here's a sample:

class RscListbox_1500: RscListbox
{
	idc = 1500;
	x = 0.507964 * safezoneW + safezoneX;
	y = 0.414996 * safezoneH + safezoneY;
	w = 0.103526 * safezoneW;
	h = 0.272013 * safezoneH;

	onLBDblClick = "_this call ACS_fnc_execute;";
};

Using this method, you can eliminate those 2 useless scripts. This might even be able to solve the performance issue you've been having. It seems like you're creating too many scripts at the same time and doing too much work, crowding the scheduler. It is very possible to significantly lengthen a script's runtime by having too many scripts running.

Share this post


Link to post
Share on other sites

WOW!!! I did not know this was possible, thank you DreadedEntity! :)

So if I call the function within my dialog (like as you have shown), I could just use the script compile preprocessFileLineNumbers to store the function that the dialog is calling, within the mission file?

Share this post


Link to post
Share on other sites

Ok, it seems I have now found the actual problem.

I have an lbClear script that executes after each combo box click within my .pbo. (in order to refresh items in their respected Category)

Because the mission code is somewhat faster than the ".pbo" code, it refreshes after the new items are loaded. *ughhhh*

Is there ways to halt the "lbClear" until the custom code has finished? (And is it possible to use scriptDone or waitUntil, for this?)

Thanks,

Rawner135

Also: Tried the call method, it seems to run a little bit faster. But eh, its more efficient than my 2 scripts I made. ;)

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
Sign in to follow this  

×