[solved] Handling item interaction

Started by Tamanegi, Thu 04/10/2012 20:47:26

Previous topic - Next topic

Tamanegi

I found another thread about a similar problem, but I can't relate it to how I want to do this.

This is my mouse click function. In short: I only use the Interaction and Use_Inv cursors; left-click walks on empty space or interacts with hotspots/characters/items, right-click either looks at hotspot/character/item or changes the Use_Inv cursor back to Interaction.

Code: AGS
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
  {
  }
  else if (button == eMouseLeft) 
  {
    if (Game.GetLocationName(mouse.x, mouse.y)!="") // if cursor is over interesting place
      ProcessClick(mouse.x,mouse.y, eModeInteract);
    else // if only empty space
      ProcessClick(mouse.x,mouse.y, eModeWalkto);
  }
  else if (button == eMouseRight) // right-click
  {   
    if (mouse.Mode==eModeUseinv) // if using inventory item: stop doing it
      mouse.Mode=eModeInteract;
    else // if not, look at clicked thing
      ProcessClick(mouse.x,mouse.y, eModeLookat);
  }
  else if (button == eMouseLeftInv) // left-click on inventory item
  {
    tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    if (tInv.IsInteractionAvailable(eModeInteract))
    {
      tInv.RunInteraction(eModeInteract);
    }
    else
    {
      player.ActiveInventory=tInv;
      mouse.Mode=eModeUseinv;
    }    
  }
  else if (button == eMouseRightInv) // right-click on inventory item
  {
    tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    tInv.RunInteraction(eModeLookat);
  }
}

Now what I want is to first check whether an inventory item has a set Interaction action before the cursor changes to Use_Inv when LMB is clicked and instead use that if there is one. But that part, the clicks on inventory items, does not work. I did override the inventory click processing in the general settings.

EDIT: Problem solved; the inventory GUI was set to "pause game when visible", and the very first check in the function says to do nothing if game is paused, effectively disabling all clicks on the GUI. I put the "eMouseRightInv" and "eMouseLeftInv" checks before the pause check and everything works smoothly.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

SMF spam blocked by CleanTalk