OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting General => Topic started by: ModestNovice on 24 Oct 2009, 06:29:48
-
Hello, I have this function here:
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:
[
"clm_dlgBank",
202,
true,
[
[
303,
"ButtonDown",
"hint 'Close Button Clicked'"
]
]
] spawn CLM_DlgCtrl;
But I keep getting:
Error ctrlAddEventHandler: Type Number, expected control
What am I doing wrong?
-
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.
((findDisplay DIALOGIDDHERE) displayCtrl (_x select 0)) ctrlAddEventHandler [_x select 1, call (_x select 2)];
-
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
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:
[
"clm_dlgBank",
202,
true,
[
[
true,
202,
"OnLoad",
"hint 'DIALOG OPEN'"
],
[
false,
303,
"ButtonDown",
"hint 'CLOSE BUTTON'"
]
]
] spawn CLM_DlgCtrl;
-
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:
onLoad = "hint 'DIALOG OPEN'";
-
ah ok, Im such a noob :(.
Thanks mate