Hello.
I have a problem with scripting.
I cannot pick up item from inventory gui when left-clicking on them. But in default demo game is worked.
mouse.Mode = eModeInteract;
, not helped me.
(http://s2.uploads.ru/d/QdDkx.png)
When i click on book in inventory-gui, cursor changed to 'pointer' and not change back to 'pick up' icon.
Global script is here (http://pastebin.com/UgkddX0g)(AGS 3.3.2.0).
In searching i find much deprecated code, what not work in my version AGS.
You have to set the cursor image to the active inventory image, if I understand what it is you are trying to do...
New morning, fresh head.
For found item under cursor (in 'repeatedly_execute()'):
InventoryItem * item;
function repeatedly_execute()
{
item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
}
Need setting 'Inventory: Override built-in inventory window click handling = True.
For pickup item from inventory (by left click) and release (by right click):
function on_mouse_click(MouseButton button)
{
if (button == eMouseLeftInv) {
player.ActiveInventory = item;
mouse.ChangeModeGraphic(eModeUseinv, item.CursorGraphic);
}
if (button == eMouseRight)
{
if (player.ActiveInventory != null) {
mouse.Mode = eModePointer;
player.ActiveInventory = null;
}
}
}
For using item on object in room-script:
function UseBook()
{
InventoryItem * item = player.ActiveInventory;
Object * obj = Object.GetAtScreenXY(mouse.x, mouse.y);
// compare item and object
// ...
}
You don't need that global variable or the rep_exe code; you can access the clicked item using inventory[game.inv_activated] in your eMouseLeftInv block.
this:
mouse.ChangeModeGraphic(eModeUseinv, item.CursorGraphic);
should be the default behavior, you should not need that line. Try removing it.
Using an item on a room object is done using the "use inventory on" event, which creates a function named "oObject_Useinv". In there you don't compare item and object but player.ActiveInventory and item. (Since we already know which object was clicked.)
I think you can do something like this indeed :smiley:
function on_mouse_click(MouseButton button)
{
InventoryItem*i = inventory[game.inv_activated];
if (button == eMouseLeftInv)
{
if (mouse.Mode == eModeUseinv) i.RunInteraction(eModeUseinv); // use current item with i
else player.ActiveInventory = i; // select activated item
}
else if (button == eMouseRight)
{
if (mouse.Mode == eModeUseinv)
{
player.ActiveInventory = null; // deselect activated item
mouse.Mode = eModePointer;
}
}
}
Then I think you can use to check the mouse mode over the inventory window in this way
// rep_exe
GUIControl*theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl == invCustomInv) // Mouse over inventory window ("invCustomInv" or the name you have replace in the editor)
{
// Change mouse mode
}
else if (theControl == null) // The mouse is not over a control
{
// Change mouse mode
}