Deselect inventory item when selecting a new one [SOLVED]

Started by Jleger91, Wed 09/04/2025 18:07:40

Previous topic - Next topic

Jleger91

When in the inventory and selecting between two items, the player is only able to select one item and then has to leave the inventory and use the scroll bar before going back into the inventory and selecting the correct item. Once an item is grabbed in the inventory, the player can no longer select an inventory item. How do I fix this?  :confused:

Eon_Star

The logic of the inventıry is like that.
Player selects one item from the inventory. Then chooses what to do with it: Use it on other inventory object or on a hotspot. Means, you cannot use the selected inventory item on another inventory item to select that one.

This is the basic. Is this the right answer to your question?

brushfe

Do you mean you'd like a way to deselect the currently selected item without leaving the inventory screen? If so, some games add a button in the inventory menu that returns the cursor to the default mode.

Khris

Again, please mention the template. If it's the Sierra template, you can click on the arrow button below the inventory items to deselect the current item.
By scroll bar, did you mean the icon bar up top?

Crimson Wizard

#4
First of all, you need to clarify few things:
1. Which template do you use, or, if you have started from empty template, then how does your gui look like and what script do you have for inventory.
2. How exactly do you want it to work.

I am not fully certain if this is what you're asking, but if you really want to swap a selected item when player clicks on another item, then it's done in on_mouse_click where you handle eMouseLeftInv. In a common case it would look something like this:

Code: ags
function on_mouse_click(MouseButton button)
{
   ..... some code here

    // this means - left mouse click on some inventory item
    if (button == eMouseLeftInv)
    {
        // select a new item regardless of whether one is already selected or not
        player.ActiveInventory = inventory[game.inv_activated];
    }
}

But before applying this code you need to double check which inventory controls do you already have in script.

Jleger91

#5
@Crimson Wizard
Using Sierra template.
Exactly, regardless of whether an inventory item is selected, I want the clicked inventory item to be selected.
Entered this code under on_mouse_click() in globalScript.asc and it didn't work

Crimson Wizard

#6
Quote from: Jleger91 on Fri 11/04/2025 16:30:57Entered this code under on_mouse_click() in globalScript.asc and it didn't work

Go to General Settings -> Inventory -> Override builtin inventory window click in script -> Enable.

But then you also will have to script other actions on inventory, such as using other verbs.

Code: ags
    if (button == eMouseLeftInv)
    {
        // if clicked using a "pointer" verb or other selected item,
        // then switch to a clicked item
        if (mouse.Mode == eModePointer || mouse.Mode == eModeUseInv)
        {
            mouse.Mode = eModeUseInv;
            player.ActiveInventory = inventory[game.inv_activated];
        }
        // if clicked using another verb (like "Look"), then run a corresponding interaction
        else
        {
            inventory[game.inv_activated].RunInteraction(mouse.Mode);
        }
    }


Also, keep in mind that if you do it this way, then you won't be able to use items on items.

Jleger91

@Crimson Wizard
Thank you. Enabling override in general settings and the code that you posted first works perfectly.

SMF spam blocked by CleanTalk