Hey! I'm having a bit of a problem right now, the thing is: I don't want to clog my global script too much with GUI functions and similar but I'm not sure if you can call GUI events through custom script files (I've tried to just copy the functions over, but that doesn't work), do I need to place GUI events in the global script or is there a comprehensible way to split my code into several scripts?
GUI event handlers need to be in the global script- but nothing stops you from putting the actual functions that are called into a separate one.
..this will look like
function btnMyButton1_Click(GUIControl *control, MouseButton button)
{
GuiScript_OnMyButtonClick();
}
Or even
function btnMyButton1_Click(GUIControl *control, MouseButton button)
{
GuiSystem.OnMyButtonClick();
}
(if you prefer writing in full OO-style)
Yeah that's what I figured when I played around a bit, it would be much more intuitive to be able to call events from custom scripts though, thanks for the quick answer. :)
Just in case it isn't clear, you can in theory use a single global script function for almost all GUI events.
The function that is created by AGS is only a suggestion, you don't have to stick to it. All you need to do is enter your function's name into the field next to the event.
// module header
import Buttons(Button *b);
// module script
void Buttons(Button *b) {
if (b == btnSave) {
// handle left click on save button
}
...
}
And in the global script:
void HandleGUIClicks(GUIControl *gc, MouseButton button) {
if (button != eMouseLeft) return;
if (gc.AsButton != null) Buttons(gc.AsButton);
...
}
Now enter "HandleGUIClicks" into every button's on click event field.
That helped me tremendously, thanks! My keypad gui just got about 10 times smaller in code. Thanks a lot. :)