Inventory question

Started by stuh505, Mon 04/04/2005 05:34:00

Previous topic - Next topic

stuh505

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?

Radiant

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.

stuh505

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

Scummbuddy

#3
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
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

stuh505

#4
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!

strazer

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:

Code: ags

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?

stuh505

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!

strazer

You're welcome. :)

Btw, instead of

Code: ags

inventory[game.inv_activated]


you could also use

Code: ags

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.

SMF spam blocked by CleanTalk