Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: poc301 on Fri 20/03/2009 15:30:59

Title: Which cursor mode activates inventory items in GUI? *RESOLVED*
Post by: poc301 on Fri 20/03/2009 15:30:59
I have looked through a LOT of messages on here, trying to find out what my problem is on my custom inventory GUI.

I have a button called "Use".

When clicked, I want this use button to change cursor modes to whatever mode will allow me to Use, Activate, etc, the inventory item's "Interact Inventory Item" code...

Its driving me nuts..  I've tried the interact mode, use inventory mode, etc, etc..  Nothing works..

Any advice?

Thanks,

Bill
Title: Re: Which cursor mode activates inventory items in GUI?
Post by: magintz on Fri 20/03/2009 15:44:49
Not sure if it will work but have you made sure that if you're using a custom inventory GUI that you've enabled the option ot handle inventory clicks in script rather than default, and that inventory clicks are processed within the global scripts on_mouse_click section such as:


function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
if(button == eMouseLeftInv) // Left mouse button clicked within inventory
    {
      // Do something
    }
}


I'm a bit rushed for time so can't explain much more but hope this helps.
Title: Re: Which cursor mode activates inventory items in GUI?
Post by: OneDollar on Fri 20/03/2009 15:56:05
Edit:magintz posted while I was typing, but I'll add my answer anyway...

The default handling of the inventory GUI object means that clicking on an inventory item while the mouse is set to the 'Interact' option doesn't call the 'Interact inventory item' event, but just makes the clicked inventory item the active inventory item and changes the mouse cursor mode to eModeUseInv. This is because 99% of the time you don't actually want to use the item, you want to take it out of the inventory to use with something else.

To override this default handling you need to go into the General Settings and set the 'Handle inventory clicks in script' option to true. Then you need to edit the on_mouse_click function in the global script, adding extra conditionals for when button ==  eMouseLeftInv (for left clicking on an inventory item) and button == eMouseRightInv (for right clicking). Then you need to code your own interactions.

An alternative method (without changing the default inventory handling) is to create a new mouse cursor, (or use, say, Usermode1) and make you GUI button change the mouse cursor to this mode. Then in the inventory item events create a function for 'Other click on inventory item' and do something like
function iKey_OtherClick()
{
  if (mouse.Mode == eModeUsermode1) {
    Display("I'm using the object");
  }
}
Title: Re: Which cursor mode activates inventory items in GUI?
Post by: poc301 on Fri 20/03/2009 16:06:39
Thanks to both of you.

The usermode2 option was perfect for what I am doing (the game is complete and in beta, so this is the less complicated work-in for it). 

It works great!

Thanks again,

Bill