Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bentelk on Mon 11/10/2010 10:41:01

Title: having trouble with scripting logic
Post by: bentelk on Mon 11/10/2010 10:41:01
I'm trying to handle click/right-click events somewhat differently from the AGS default, and am running in to trouble getting inventory clicks recognized.  I have a custom inventory bar on the bottom of the screen which is always displayed (and I do have "handle inventory clicks in script" set to "true"), and the logic seems to be acknowledging and responding to clicks upon it sometimes, but not others!

here is the relevant code:

function on_mouse_click(MouseButton button)
{

  // "is the game paused" and other logic is here

  InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  LocationType loc = GetLocationType(mouse.x, mouse.y);

  if(i != null)
  {
    Display("clicked on an item!"); // the code gets to this point when I click an item
  }

  if(button == eMouseRight) // right-click is always "look at"
  {
    if(i != null)
    {
      Display("right-clicked on an item."); // the code does NOT get to this point!

      // some more code in here, but it's beside the point
    }
    // there's a bunch more code in here, but it's beside the point
  }
  else if(button == eMouseLeft) // left click is always an interaction
  {
    if(i != null)
    {
      Display("left-clicked on an item."); // the code does NOT get to this point!

      // more irrelevant code

the "button" variable seems to be being evaluated correctly, because I can get responses out of clicking and right clicking on other objects (following the "if(i != null)" block there are "else if(loc == eLocationObject)" blocks, and others, which are reached.

it _seems_ like the "i" variable is somehow getting cleared, but that doesn't make any sense!  there must be something else I'm missing... any help would be greatly appreciated :)

[edit] oh, and because I worried that having two "Display" calls in rapid succession might somehow mess with things, I did try removing the first Display("clicked on an item!"); however this has not helped anything.
Title: Re: having trouble with scripting logic
Post by: Khris on Mon 11/10/2010 11:00:01
You have to use "eMouseLeftinv" and "eMouseRightinv" for clicks on inventory items.

These only work for a click on an item, not the whole inventory window.
Title: Re: having trouble with scripting logic
Post by: monkey0506 on Mon 11/10/2010 18:32:32
You didn't specify that you need to intercept clicks on the InvWindow control itself you can use the on_event function such as:

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) { // or eEventGUIMouseUp depending which one you want to intercept
    if (data == invInventory.OwningGUI.ID) { // where invInventory is the script name of your InvWindow
      GUIControl *gcat = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if (gcat == invInventory) {
        Display("clicked on the inventory window");
      }
    }
  }
}