[SOLVED] Letting Go of Inventory Items without Losing Them

Started by cipberbloom, Wed 03/11/2021 03:56:09

Previous topic - Next topic

cipberbloom

Hey there everyone -

I'm looking to use a right click to drop an inventory item back into the inventory (in rooms, outside of the inventory GUI itself). I've tried quite a few things and think I must be missing something simple. Right now in on_mouse_click in the global script:

Code: ags

// called when a mouse button is clicked
function on_mouse_click(MouseButton button)


I have this at the end:
Code: ags

// drop item back into the inventory
  else if (button == eMouseRight && player.ActiveInventory != null)
  {
    player.ActiveInventory = null;
  }


My inventory GUI is not set to pause.


Here are the contents of on_mouse_click in their entirety:

Code: ags

// called when a mouse button is clicked
function on_mouse_click(MouseButton button)
{
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused())
  {
    // game is paused, so do nothing (i.e. don't process mouse clicks)
  }
  
  // walk anywhere even if walk is not the active mode START
  else if ((GetWalkableAreaAtScreen(mouse.x, mouse.y) != 0 || (GetLocationType(mouse.x, mouse.y) == eLocationNothing)) && (button == eMouseLeft))
  {
    Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }
  // walk anywhere even if walk is not the active mode STOP
  
  else if (button == eMouseLeft)
  {
    // left-click, so try using the current mouse cursor mode at this position
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode );
  }

  else if (button == eMouseRight || button == eMouseWheelSouth){
    // right-click or mouse wheel down will cycle the mouse cursor mode forwards
    mouse.SelectNextMode();
  }

  else if (button == eMouseMiddle)
  {
    // middle-click makes the character walk to clicked area, regardless of cursor mode
    Room.ProcessClick(mouse.x, mouse.y, eModeWalkto);
  }

  else if (button == eMouseWheelNorth)
  {
    // mouse wheel up will cycle the cursor mode backwards
    mouse.SelectPreviousMode();
  }

    // drop item back into the inventory
  else if (button == eMouseRight && player.ActiveInventory != null)
  {
    player.ActiveInventory = null;
  }
}


Nothing happens. The player is still holding the inventory object they've picked up, whether chosen from already acquired inventory, or from a room.

Hope you all are well!

Thanks in advance...   ;-D

Gilbert

That's because you already have this part:
Code: ags

  else if (button == eMouseRight || button == eMouseWheelSouth){
    // right-click or mouse wheel down will cycle the mouse cursor mode forwards
    mouse.SelectNextMode();
  }


So the condition for clicking the right button has already been captured and so the last 'else' part will not be checked.
(I haven't checked the codes thoroughly though, so there may be other lines that will clash with this.)

One (not very elegant) solution is to put this inside the above part:
Code: ags

  else if (button == eMouseRight || button == eMouseWheelSouth){
    // right-click or mouse wheel down will cycle the mouse cursor mode forwards
   if (button == eMouseRight && player.ActiveInventory != null) player.ActiveInventory = null;
   else mouse.SelectNextMode();
  }



Khris

The existing code you have is Sierra interface code, where a right click is used to cycle through cursor modes.
If you're planning to use a two button interface instead, you need to rewrite all the on_mouse_click code.

Cassiebsg

What they said.  (nod)

Just wanted to add that to catch mouse clicks on inventory window you have eMouseLeftInv and eMouseRightInv.
There are those who believe that life here began out there...

cipberbloom

Well that was a bit embarrassing.  :-[

I've got it working now (separate to eMouseWheelSouth; didn't want to affect cycling through modes).

Thanks very much to you Gilbert, Khris, and Cassie!

SMF spam blocked by CleanTalk