OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: ModestNovice on 24 Oct 2009, 06:29:48

Title: CtrlAddEventHandler [SOLVED]
Post by: ModestNovice on 24 Oct 2009, 06:29:48
Hello, I have this function here:
Code: [Select]
CLM_DlgCtrl =
{
_dialog = _this select 0;
_dlgIDD = _this select 1;
_code = _this select 2;
_codeArray = _this select 3;

_ok = createDialog _dialog;

if (!_code) exitWith {};

{
((findDisplay _dlgIDD) displayCtrl (_x select 0)) ctrlAddEventHandler [(_x select 1), (_x select 2)];
} foreach _codeArray;

nil;
};


In which I am calling with:
Code: [Select]
[
"clm_dlgBank",
202,
true,
[
[
303,
"ButtonDown",
"hint 'Close Button Clicked'"
]
]
] spawn CLM_DlgCtrl;


But I keep getting:
Code: [Select]
Error ctrlAddEventHandler: Type Number, expected control

What am I doing wrong?
Title: Re: CtrlAddEventHandler
Post by: Mandoble on 24 Oct 2009, 09:07:36
Your code array is:
[[303, "ButtonDown", {hint "Hello"}]]

But 303 is a control number (IDC), not a control. You need to use displayCtrl (http://www.ofpec.com/COMREF/index.php?action=details&id=528&game=All) command to obtain a control object from its IDC and the display of its dialog.

To get the display object you may use findDisplay (http://www.ofpec.com/COMREF/index.php?action=details&id=558&game=All) command passing the IDD number of your dialog.

Code: [Select]
((findDisplay DIALOGIDDHERE) displayCtrl (_x select 0)) ctrlAddEventHandler [_x select 1, call (_x select 2)];
Title: Re: CtrlAddEventHandler
Post by: ModestNovice on 24 Oct 2009, 22:12:49
Works, but now I want to add the ability to add events to the main IDD.

this throws no error, but doenst hint when I open the dialog:

DO NOT USE
Code: [Select]
CLM_DlgCtrl =
{
_dialog = _this select 0;
_dlgIDD = _this select 1;
_code = _this select 2;
_codeArray = _this select 3;

_ok = createDialog _dialog;

if (!_code) exitWith {};

{
if (_x select 0) then
{
(findDisplay _dlgIDD) displayAddEventHandler [(_x select 2), (_x select 3)];
}
else
{
((findDisplay _dlgIDD) displayCtrl (_x select 1)) ctrlAddEventHandler [(_x select 2), (_x select 3)];
};
} foreach _codeArray;

nil;
};

Calls With:
Code: [Select]
[
"clm_dlgBank",
202,
true,
[
[
true,
202,
"OnLoad",
"hint 'DIALOG OPEN'"
],
[
false,
303,
"ButtonDown",
"hint 'CLOSE BUTTON'"
]
]
] spawn CLM_DlgCtrl;


Title: Re: CtrlAddEventHandler [SOLVED]
Post by: Mandoble on 24 Oct 2009, 23:15:43
You are adding an "OnLoad" EH after the dialog has been already created and loaded, so it will have no effect.

Define the onLoad EH in the description.ext, inside your dialog class:
Code: [Select]
   onLoad = "hint 'DIALOG OPEN'";
Title: Re: CtrlAddEventHandler [SOLVED]
Post by: ModestNovice on 25 Oct 2009, 03:31:27
ah ok, Im such a noob :(.

Thanks mate