Mouse back to Interact after using inventory item

Started by steptoe, Thu 26/07/2012 16:50:41

Previous topic - Next topic

steptoe

Changing the mouse back to Hand Interact after using inventory does not seem to work with this code and returns to Lookat: (unless there is a conflict somewhere?)


Code: AGS
function on_event (EventType event, int data)
{

  if (event == eEventLoseInventory) 
  {
  mouse.Mode = eModeInteract;
  } 
  if (event == eEventGUIMouseDown && mouse.IsButtonDown(eMouseRight) && player.ActiveInventory != null && data == gInventory.ID) 
  {
  GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (theControl==invCustomInv) //the InvWindow
  {
  InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  if (i == null)
  { 
  player.ActiveInventory = null;  
  mouse.Mode=eModeInteract;
 }
 }
 }
 }


cheers if you could help


Crimson Wizard

#1
That's usually monkey's or Khris's right to say this ;), but...
for the love of God, please, please! use indentation! It is really hard to understand the code without one. And probably will help you too.
Here's the example of what I am talking about, your code with fixed indentation:

Code: AGS

function on_event (EventType event, int data)
{
  if (event == eEventLoseInventory) 
  {
     mouse.Mode = eModeInteract;
  } 
  if (event == eEventGUIMouseDown && mouse.IsButtonDown(eMouseRight) && player.ActiveInventory != null && data == gInventory.ID) 
  {
     GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
     if (theControl==invCustomInv) //the InvWindow
     {
        InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
        if (i == null)
        { 
           player.ActiveInventory = null;  
           mouse.Mode=eModeInteract;
        }
     }
   }
}


See? now it is much easier to understand what's what, you can distinct different conditional braches at a single glance.

Okay, now, about your problem.
Do I understand correct that you want mouse cursor should change to Interact mode every time after you used the inventory? Then, I believe, your code does not do what it has to.
Let's take the first piece of your code:
Code: ags

if (event == eEventLoseInventory) 
{
   mouse.Mode = eModeInteract;
} 

This code means that every time character looses inventory item (an item is removed from inventory) the mouse cursor mode will be changed to Interact regardless of what it was. That is - if it was Look cursor, or Talk cursor - or any other cursor - it will still change to Interact. Is it really what you want?

The second part of code is executed when you press mouse over Inventory Window. It changes mouse cursor to Interact and removes active inventory item if there's no other item under the cursor.

In other words, there's nothing in this code related to inventory item being used at all.

There are few ways to do what you want, depending on how you handle interactions in general.
For example, you have this in on_mouse_click function (I copied your code from the other recent thread where you posted it):
Code: ags

function on_mouse_click()
{
   if (IsGamePaused() == 1)
   {
     // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button == eMouseLeft) 
   {
      ProcessClick( mouse.x, mouse.y, mouse.Mode );
   }
   ..... your other code ......
}


Change the code this way:
Code: ags

   ...
   else if (button == eMouseLeft) 
   {
      int mode_was = mouse.Mode; // remember the mouse mode before interaction
      int has_interaction = IsInteractionAvailable (mouse.x, mouse.y, mouse.Mode); // will we have any interaction here?
      ProcessClick( mouse.x, mouse.y, mouse.Mode ); // do actual interaction

      // if we had some interaction and mode was 'use inventory item', then...
      if (mode_was == eModeUseinv && has_interaction != 0)
      {
         // change mode to Interact
         mouse.Mode = eModeInteract;
      }
   }
   ...


I should underline that the code above is an example of how it could be done. I can't guarantee it is the most optimal way to do this in general or for your case.

steptoe

#2
Cheers Crimson Wizard,

It's ok to join the Monkey and Khris brigade, it's how we all learn  :P

Message understood.

Will go over your code.

EDIT: Returns to Interact but no modes... Eventually got it sorted

Thanks very much

SMF spam blocked by CleanTalk