Custom Inventory not registering left clicks [SOLVED]

Started by Scavenger, Mon 11/05/2009 22:13:23

Previous topic - Next topic

Scavenger

So I'm making a somewhat BASS/Broken Sword like interface for my game, and I've come across a problem I can't solve, but know the answer lies SOMEWHERE I have probably stared at for ages.  I've made everything else work, from interaction, right click, context sensitive mouse graphics, and popup inventories, but I just can't get the cursor to set itself to Use Inventory Item, turning the cursor into that inventory item and having it be the mode you're using. player.Activeinventory never actually becomes anything but null, and I can't see where I'm going wrong. I've tried workarounds, toggling Handle Inventory Clicks in Script, and everything, I just can't see it.

Here's where I changed the code that affects the mouse cursor:

Code: ags
function repeatedly_execute() {


  // put anything you want to happen every game cycle, even when
  // the game is paused, here

  if (IsGamePaused() == 1) return;

if (player.ActiveInventory == null) {
if (GetLocationType (mouse.x, mouse.y) == eLocationHotspot) {
  vhThingover = Hotspot.GetAtScreenXY (mouse.x, mouse.y);
  mouse.UseModeGraphic (hotspot[vhThingover.ID].GetProperty ("mousetype"));
}
else if (GetLocationType (mouse.x, mouse.y) == eLocationCharacter) {
  vcThingover = Character.GetAtScreenXY (mouse.x, mouse.y);
  mouse.UseModeGraphic (character[vcThingover.ID].GetProperty ("mousetype"));
}
else if (GetLocationType (mouse.x, mouse.y) == eLocationObject) {
  voThingover = Object.GetAtScreenXY (mouse.x, mouse.y);
  mouse.UseModeGraphic (object[voThingover.ID].GetProperty ("mousetype"));
}
else mouse.UseModeGraphic (0);}
else mouse.Mode = eModeUseinv;

if (mouse.y > 219)
{
  if (player.ActiveInventory != null) mouse.Mode = eModeInteract;
  gInventory.Visible = true;
  gOverhotspot.SetPosition (gOverhotspot.X, 210);
}
else if (gInventory.Visible == true)
{
  gInventory.Visible = false;
  gOverhotspot.SetPosition (gOverhotspot.X, 230);
}
}


Code: ags

  // 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 && player.ActiveInventory == null) 
    {
      //Left Mouse Button triggers an interaction with the subject.
      if (IsInteractionAvailable (mouse.x, mouse.y, eModeInteract)) ProcessClick(mouse.x, mouse.y, eModeInteract);
      else ProcessClick (mouse.x, mouse.y, eModeWalkto);
    }
    else if (button == eMouseLeft && player.ActiveInventory != null)
    {
      //Use an Inventory Item (If active)
      ProcessClick (mouse.x, mouse.y, eModeUseinv);
    }
  else if (button == eMouseRight && player.ActiveInventory == null)
  {
    // right-click triggers an examination.
    ProcessClick(mouse.x, mouse.y, eModeLookat);
  }
  else if (button == eMouseRight && player.ActiveInventory != null)
  {
    // right-click with an active inventory sends it back to the inventory window.
    player.ActiveInventory = null;
  }
  else if (button == eMouseMiddle) { 
    // Middle-button-click, default make character walk to clicked area (a little shortcut)
    // Could have been just "player.Walk(mouse.x,mouse.y)", but it's best to
    // leave our options open - what if you have a special script triggered
    // on "walking" mode?
    ProcessClick(mouse.x, mouse.y, eModeWalkto); 
  }


Using 3.1.2 SP1. I'm sure I'm just doing something really stupid and not seeing it.


All my game files are in here, it's just a shell at the moment, nothing but programmer graphics and bare-bones testing stuff.
http://www.2dadventure.com/upload/Cyberpunk.zip

Please can someone say where I'm going wrong? :3

Khris

At the end of the rep_ex, you have
Code: ags
if (mouse.y > 219)
{
  if (player.ActiveInventory != null) mouse.Mode = eModeInteract;


Change that to
Code: ags
  if (mouse.y > 219)
  {
    if (!gInventory.Visible) mouse.Mode = eModeInteract;


With your code, as soon as the cursor changed to the icon (and the mode to eModeUseinv), the cursor mode was immediately reset to eModeInteract. That's why it looked as if nothing had happend.

The change makes the mouse mode change get called only once, right before the inventory is displayed.

Scavenger

Quote from: KhrisMUC on Mon 11/05/2009 22:40:18
With your code, as soon as the cursor changed to the icon (and the mode to eModeUseinv), the cursor mode was immediately reset to eModeInteract. That's why it looked as if nothing had happend.

The change makes the mouse mode change get called only once, right before the inventory is displayed.

Ah, so that's where it was going wrong. It works perfectly now, thanks :D

SMF spam blocked by CleanTalk