Forum rules - please read before posting.

After almost 4 years, new problem without solution! (for me)

2»

Comments

  • Sorry I misunderstood, this is the full log:

    Uncheck Prevent interactions? in your InventoryBox element.

    Double clicking to teleport (and disable this option when a boolean variable is false)

    This feature is available in the current release.

    Use "." to skip dialogues

    Define an input named "SkipSpeech" in the Input Manager, and set "." (no quotes) in its Positive Button field.

  • Unchecked it. Since it doesn't allow to interact with inventory items, nothing was written in the log

  • So, what's next now?

  • edited June 2024

    I need to be clear: is the original issue of items becoming selected at the wrong time now resolved, such that the only remaining issue your following request?

    If heldTime equals or is greater than, let's say, 0.15, the item cannot be selected, otherwise if heldTime is less than 0.15, you can select the item.

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class VerbCoin : MonoBehaviour
    {
    
        public float maxHoldTime = 0.5f;
        public float selectTime = 0.15f;
        private float heldTime;
    
    
        private void Update ()
        {
            if (heldTime < 0f && !Input.GetMouseButton (0)) heldTime = 0f;
    
            if (heldTime >= 0f &&
                Input.GetMouseButton (0) &&
                (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
                KickStarter.stateHandler.IsInGameplay () &&
                !KickStarter.playerMenus.IsInteractionMenuOn ())
            {
                // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
    
                heldTime += Time.deltaTime;
                if (heldTime >= maxHoldTime)
                {
                    // Open the Interaction menu
                    if (KickStarter.runtimeInventory.hoverItem != null)
                    {
                        // For an inventory item
                        KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
                    }
                    else
                    {
                        // For a Hotspot
                        KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
                    }
                    heldTime = -1f;
                }
                else if (heldTime < selectTime)
                {
                    KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
                    heldTime = -1f;
                }
            }
            else if (!Input.GetMouseButton (0) &&
                (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
                KickStarter.stateHandler.IsInGameplay () &&
                KickStarter.playerMenus.IsInteractionMenuOn ())
            {
                KickStarter.playerMenus.CloseInteractionMenus ();
                heldTime = 0f;
            }
        }
    
    }
    
  • That didn't work but I had a better idea, too bad I couldn't execute it correctly

    If the game detects that the mouse button was lifted before maxHoldTime was elapsed then the element will be selected, otherwise the interactions menu will be displayed and the item will not be selected. This is what I tried to do, without success because it didn't work

    using UnityEngine;
    using System.Collections;
    using AC;

    public class VerbCoin : MonoBehaviour
    {

    public float maxHoldTime = 0.5f;
    private float heldTime;
    
    
    private void Update ()
    {
        if (Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            !KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
    

    if (KickStarter.runtimeInventory.SelectedItem != null) return;
    heldTime += Time.deltaTime;
    if (heldTime >= maxHoldTime)
    {
    // Open the Interaction menu
    if (KickStarter.runtimeInventory.hoverItem != null)
    {
    // For an inventory item
    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
    }
    else
    {
    // For a Hotspot
    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
    }
    heldTime = 0f;
    }

        }
    
        else if (!Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            KickStarter.playerMenus.CloseInteractionMenus ();
            heldTime = 0f;
        }
         else 
        {
            heldTime = 0f;
        }
    
        if (Input.GetMouseButtonUp(0) && KickStarter.runtimeInventory.hoverItem != null && !KickStarter.playerMenus.IsInteractionMenuOn () && heldTime < maxHoldTime)
            {
                KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
                heldTime = -1f;
            }
        else return;
    }
    

    }

  • It may be something more along these lines:

    using UnityEngine;
    using AC;
    
    public class VerbCoin : MonoBehaviour
    {
    
        public float maxHoldTime = 0.5f;
        private float heldTime;
    
    
        private void Update ()
        {
            if (Input.GetMouseButton (0) &&
                (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
                KickStarter.stateHandler.IsInGameplay () &&
                !KickStarter.playerMenus.IsInteractionMenuOn ())
            {
                // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
                if (KickStarter.runtimeInventory.SelectedItem != null) return;
    
                heldTime += Time.deltaTime;
                if (heldTime >= maxHoldTime)
                {
                    // Open the Interaction menu
                    if (KickStarter.runtimeInventory.hoverItem != null)
                    {
                        // For an inventory item
                        KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
                    }
                    else
                    {
                        // For a Hotspot
                        KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
                    }
                    heldTime = 0f;
                }
            }
            else if (!Input.GetMouseButton (0) &&
                KickStarter.runtimeInventory.hoverItem != null &&
                KickStarter.stateHandler.IsInGameplay () &&
                !KickStarter.playerMenus.IsInteractionMenuOn () &&
                heldTime > 0f && heldTime < maxHoldTime)
            {
                KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
                heldTime = 0f;
            }
            else if (!Input.GetMouseButton (0) &&
                (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
                KickStarter.stateHandler.IsInGameplay () &&
                KickStarter.playerMenus.IsInteractionMenuOn ())
            {
                KickStarter.playerMenus.CloseInteractionMenus ();
                heldTime = 0f;
            }
        }
    
    }
    
  • Made a FREAKING oopsie, I happened to update to 1.8 today to see if I could expand my options for fixing the bugs that still occur nowadays, and I found myself getting the following message:

    Assets\VerbCoin.cs(44,54): error CS1503: Argument 1: cannot convert from 'AC.InvItem' to 'AC.InvInstance'.

    Fortunately, not all is lost, because I would like to know if there is any way that if you hold down the left mouse button over an Inventory Item, you could activate the boolean: "Prevent Selection?"

  • Assets\VerbCoin.cs(44,54): error CS1503: Argument 1: cannot convert from 'AC.InvItem' to 'AC.InvInstance'.

    The Inventory system's API was changed in v1.72 - you can find details about it here.

    If you'd like to share the VerbCoin script, I can make the necessary amendment.

    is any way that if you hold down the left mouse button over an Inventory Item, you could activate the boolean: "Prevent Selection?"

    You can alter the field through script. As with any Manager field, right-click its label to get an API reference you can copy to the text buffer.

    I'd say that altering this field at runtime, however, would be easy to create errors and knock-on effects elsewhere. If you want to heavily customise the behaviour of Inventory menus, the best way is to set the Inventory box type to Custom Script, and then hook into the OnMenuElementClick custom event to dictate the intended behaviour:

    void OnMenuElementClick (Menu _menu, MenuElement _element, int _slot, int buttonPressed)
    {
        if (_menu.title == "Inventory" && _element.title == "InventoryBox")
        {
            MenuInventoryBox inventoryBox = _element as MenuInventoryBox;
            InvInstance clickedInstance = inventoryBox.GetInstance (_slot);
            //
        }
    }
    
  • using UnityEngine;
    using AC;

    public class VerbCoin : MonoBehaviour
    {

    public float maxHoldTime = 0.5f;
    private float heldTime;
    
    
    private void Update ()
    {
        if (Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            !KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            // LMB is held down over a Hotspot or inventory item, during gameplay, and when no Interaction menu is showing
            if (KickStarter.runtimeInventory.SelectedItem != null) return;
    
            heldTime += Time.deltaTime;
            if (heldTime >= maxHoldTime)
            {
                // Open the Interaction menu
                if (KickStarter.runtimeInventory.hoverItem != null)
                {
                    // For an inventory item
                    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.runtimeInventory.hoverItem);
                }
                else
                {
                    // For a Hotspot
                    KickStarter.playerMenus.EnableInteractionMenus (KickStarter.playerInteraction.GetActiveHotspot ());
                }
                heldTime = 0f;
            }
        }
        else if (!Input.GetMouseButton (0) &&
            KickStarter.runtimeInventory.hoverItem != null &&
            KickStarter.stateHandler.IsInGameplay () &&
            !KickStarter.playerMenus.IsInteractionMenuOn () &&
            heldTime > 0f && heldTime < maxHoldTime)
        {
            KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
            heldTime = 0f;
        }
        else if (!Input.GetMouseButton (0) &&
            (KickStarter.playerInteraction.GetActiveHotspot () != null || KickStarter.runtimeInventory.hoverItem != null) &&
            KickStarter.stateHandler.IsInGameplay () &&
            KickStarter.playerMenus.IsInteractionMenuOn ())
        {
            KickStarter.playerMenus.CloseInteractionMenus ();
            heldTime = 0f;
        }
    }
    

    }

    Here is the code, thank you

  • Replace:

    KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.hoverItem);
    

    with:

    KickStarter.runtimeInventory.SelectItem (KickStarter.runtimeInventory.HoverInstance);
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.