Unselect Inventory Cursor while clicking away

Started by Phonoitypal, Mon 08/01/2024 20:53:08

Previous topic - Next topic

Phonoitypal

Hi !
I have a very noobish problem.
I want to make it so that after the cursor changes based on the item sprite, if you click 'away' , or on a hotspot that has no correlation with the "useinv"function, to make the cursor go back to normal. When I use the inventory item(along with its cursor) to a designated hotspot that that useinv function, the cursor goes back to normal(as expected), but If i dont use the item anywhere, its impossible to 'deselect' the item along with its cursor.

Sadly, so far  I failed in my attempts to do this. Can anyone help me ?


For context, I have the following script that changes my cursor based on hovering over hotspots/objects etc. I think maybe it will give more context

Code: ags
function repeatedly_execute()
{
  if (player.ActiveInventory ==null){
    if (GetLocationType(mouse.x, mouse.y) != eLocationNothing) {
        // Set the variable to true when the mouse is over a hotspot
        if (!isOverHotspot) {
            // Execute global script only when entering a hotspot
            Mouse.ChangeModeGraphic(mouse.Mode, 24);
            aMmove.Play();
        }
        isOverHotspot = true;
    } else {
        // If the mouse is not over a hotspot, execute the global script
        if (!isOverHotspot) {
            Mouse.ChangeModeGraphic(mouse.Mode, 22);
        }
        // Reset the variable
        isOverHotspot = false;
    }
}
}



BUT
 so far, I tried to do the following regarding what I tried to achieve :


Code: ags
if (player.ActiveInventory != null) //An inventory item is selected
{
  player.ActiveInventory = null;
  mouse.Mode = eModeInteract;
}

But here the problem is that it completely annihilates and ignores the useinv function, it just changes the mouse cursor after I click on an inventory and CLICK anywhere, and prevents the item's usage. I checked other threads but none of the solutions worked :( :~(  :~(

Khris

I assume you put that last piece of code inside on_mouse_click and inside the block for a specific mouse button?
Assuming you did that, you naturally also need to check GetLocationType() again (and/or the .IsInteractionAvailable() methods), like you already did in repeatedly_execute, or the code will simply fire on any click.

Phonoitypal

Hi Khris, could you please give a more detailed example ? Due to my own personal error I cannot make it work ! I think Im writting it all wrong. Could you give me an example ? And yes, I used that code on the on mouse click  event

Khris

You need something like this:

Code: ags
  if (button == eMouseLeft) {
    // left-clicking nothing with active inv item
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing && player.ActiveInventory != null) {
      player.ActiveInventory = null;
      Mouse.Mode = eModeInteract;
    }
    else Room.ProcessClick(mouse.x, mouse.y, Mouse.Mode);
  }

Phonoitypal

Quote from: Khris on Tue 09/01/2024 22:57:10You need something like this:

Code: ags
  if (button == eMouseLeft) {
    // left-clicking nothing with active inv item
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing && player.ActiveInventory != null) {
      player.ActiveInventory = null;
      Mouse.Mode = eModeInteract;
    }
    else Room.ProcessClick(mouse.x, mouse.y, Mouse.Mode);
  }



This works perfectly, thanks a lot ! my ags saviour B)

SMF spam blocked by CleanTalk