Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: stuh505 on Mon 04/04/2005 05:34:00

Title: Inventory question
Post by: stuh505 on Mon 04/04/2005 05:34:00
im using AGS 2.7 and I dont want to use any obsolete procedures

I'm not using a bunch of "mouse modes" in my game, but I want a left click on any inventory item to pick it up...a right click to look at it, and a right click after an item has been picked up to go back to the regular mouse (ie drop it back in inv)

I'm a bit confused from the documentation...where and how should I script this?
Title: Re: Inventory question
Post by: Radiant on Mon 04/04/2005 10:21:53
Try this: in the function unhandled_event, watch for GUI_MDOWN (which catches clicks on a GUI) and test if the button is left or right.
Title: Re: Inventory question
Post by: stuh505 on Mon 04/04/2005 15:10:24
it sounds like that would require my to literally detect what item the mouse was over (somehow?) and then manuallly make that item into the mouse cursor (somehow?)...isn't there an automatic way to do this?

the script in the Default game seems to handle this but I don't quite see how it works
Title: Re: Inventory question
Post by: Scummbuddy on Tue 05/04/2005 03:06:34
just because this hasnt been responded to within 12 hours is no reason to start another thread about it, and even in a new forum.


well, the "automatic" way, would be for you to go to every inv item, and on its interactions, script what should happen on left click, and right click... or you can do it radiants easier and smarter way and make a general way to handle the inv
Title: Re: Inventory question
Post by: stuh505 on Tue 05/04/2005 03:36:23
I didn't realize it would be such a big deal.Ã,  Sorry!

If we simply determine that the left button was clicked within the inventory, then wouldn't we also need to determine which item the mouse was over in order to determine which item should replace the cursor?Ã,  That's where I was confused.Ã,  Using the dimensions of inventory objects this could be calculated but not if the inventory was scrollable because I don't see any functions to tell what the scroll position is.

Anyway, I think I've worked out an easier solution which is simply to change the mouse mode to interact mode (and off again later if nothing was picked up) whenever it hovers over the inventory part...for some reason even in interact mode a right clikc still counts as looking at the itme.  But  I'm still curious how Radian'ts method would work.

Again sorry for being impatiant.Ã,  Can't help it!
Title: Re: Inventory question
Post by: strazer on Tue 05/04/2005 18:01:16
QuoteI want a left click on any inventory item to pick it up...a right click to look at it, and a right click after an item has been picked up to go back to the regular mouse (ie drop it back in inv)

How about this:

Check "Handle inventory clicks in script" in General settings, then:


function on_mouse_click(MouseButton button) {

  if (IsGamePaused() == true) {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode);
  }
  else if (button == eMouseLeftInv) { // left click on an inventory item
    player.ActiveInventory = inventory[game.inv_activated]; // equip player with item
  }
  else if (button == eMouseRightInv) { // right click on an inventory item
    ProcessClick(mouse.x, mouse.y, eModeLook); // look at inv item
  }
  else { // normal right-click
    player.ActiveInventory = null; // unequip player
    mouse.SelectNextMode();
  }

}


Is that what you're looking for?
Title: Re: Inventory question
Post by: stuh505 on Tue 05/04/2005 23:46:17
Ah, thank you!

I did not realize that there was an "ActiveInventory" property that could be set....nor a predetermined function to determine that inv item had been clicked on.  That makes it easy!
Title: Re: Inventory question
Post by: strazer on Wed 06/04/2005 00:08:25
You're welcome. :)

Btw, instead of


inventory[game.inv_activated]


you could also use


InventoryItem.GetAtScreenXY(mouse.x, mouse.y)


The difference between the two resp. the reason for game.inv_activated is not entirely clear to me. The manual states it's useful for the unhandled_event function so my guess is you shouldn't use GetAtScreenXY(mouse.x, mouse.y) in there since the game could have advanced some game loops until unhandled_event is called and the mouse coordinates would not be accurate anymore.