can a GUI event point to function not on global script

Started by eri0o, Fri 01/09/2017 02:21:22

Previous topic - Next topic

eri0o

Is it possible to make an event on a GUI point to a function not on GlobalScript.asc ? Is it normal that if I click on the three dots (...) it doesn't lead to my function?

Crimson Wizard

Quote from: eri0o on Fri 01/09/2017 02:21:22
Is it possible to make an event on a GUI point to a function not on GlobalScript.asc ? Is it normal that if I click on the three dots (...) it doesn't lead to my function?

No, that's weird AGS limitation, common solution is just to call your module function from handler in global script.

eri0o

Thanks CW, my Global Script is getting kinda long because I have lot's of GUI in my game - basically lots of different computers and stuff - and I though about separating them in modules, I didn't get Build errors, but they stopped working too. :(

So I guess I will keep adding lots of comments in the Global Script. :-\

Khris

You can use a single function for multiple events, btw. Say you have five buttons. Assign a function to the first one as usual, then copy over the event handler name to the other button's onClick events. Then redirect to your module, and use the GUIControl parameter to figure out which button was clicked:

Code: ags
// module header
import void HandleMainGUI(GUIControl *gc, MouseButton button);

// module script
void HandleMainGUI(GUIControl *gc, MouseButton button) {
  Button *b = gc.AsButton;
  if (b == btnInfo) ...
  ...
}

// GlobalScript
void MainGUIButton_OnClick(GUIControl *gc, MouseButton button) { HandleMainGUI(gc, button); }

SMF spam blocked by CleanTalk