Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Rocco on Wed 26/03/2008 00:04:34

Title: GUI activated function in module?
Post by: Rocco on Wed 26/03/2008 00:04:34
I trying to make a module with user input - gui element.

but im struggling with the GUI activate function.
It seems that this function only works in the global script.
Is this true, and is there a possibility to make this function also callable in the module?
Title: Re: GUI activated function in module?
Post by: Khris on Wed 26/03/2008 08:04:55
Afaik, no. (Workaround: check for GUI clicks in the module's rep_ex, then ClaimEvent())

Just do:
function whatever_onClick(...) {
  myModule.myFunction();
}


I'm sure you're going to publish the module together with the GUI, and the nice thing about GUIs is that if exported, their onClick functions end up in the file as well :)
Title: Re: GUI activated function in module?
Post by: naltimari on Wed 26/03/2008 19:52:34
In my modules, I check for GUI-related events:


function on_event(EventType event, int data)
{
  // check if user clicked inside myGui
  if (event == eEventGUIMouseUp && data == myGui.ID) {
    // check which control the user clicked onto
    GUIControl* ctrl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
    if (ctrl != null) {
      // user clicked over 'ctrl'
    }
    else {
      // user clicked inside GUI, but not on a specific control
    }
  }
}


eEventGUIMouseUp is triggered when the mouse button is released. There's also eEventGUIMouseDown, which is triggered when the mouse button is pressed. I usually choose to respond to the click in MouseUp, so the user can 'cancel' the click if he releases the button outside of the control in which he clicked...

Hope this helps.
Title: Re: GUI activated function in module?
Post by: Rocco on Wed 26/03/2008 20:32:47
thx, i will check your suggestions tomorrow.

problem is, there is no need for an mouse click event on this gui,
cause its a text input box, where the player have to type his name and finish with enter.
Title: Re: GUI activated function in module?
Post by: Khris on Wed 26/03/2008 20:57:20
Just use the standard [textbox_name]_OnActivate function in the global script. From within that, call the module's function. The _OnActivate one will end up in the exported GUI.
Title: Re: GUI activated function in module?
Post by: naltimari on Thu 27/03/2008 00:04:59
You can surely use Kris' suggestion, it will work and it is very straightforward.

However, if you are willing to keep all your code inside the module, which personally I find very interesting, there's a way. You must check for IsKeyPressed(13) on your module's rep_ex(), since on_key_press() won't get called whenever a textbox is present (and Enabled).


// this is the rep_ex that is inside your module
function repeatedly_execute()
{
  if (yourGUI.Visible && IsKeyPressed(13)) {
    // ok, the user has pressed 'ENTER' while your GUI was being shown;
    // provided you have only one text box inside your GUI, this check is enough
    // otherwise, you still have other things to check...
    ...
  }
}


Personally, I dont like the way text boxes are implemented. There are some issues that really should be addressed soon:

Title: Re: GUI activated function in module?
Post by: Rocco on Fri 28/03/2008 10:11:22
big thanks for your help, should be no problem to get the module to work now.  :)

khris suggestion works, the only little glitch is that i have to save a few variables global,
but this is no great problem.

@naltimare:
i think also its better to have all code in the module, so i will check your suggestion today.