Forum rules - please read before posting.

Combine inventory items when game is paused

edited March 2020 in Technical Q&A

Hi Chris:) Hope you and your family are safe!

Each item in my inventory have examine function that calls the document. I use such document for item description. So, basically one item has one document to describe it. When the document is opened it pause the game - this works as I wanted! But I can still play with items: reorder them, examine and this also works fine for me. But the issue is in that I can still combine items when game is paused. This not works for me because when I combine items it's running action list with player animation, so even if document is opened and game is paused my player start to play animation and do other stuff that I have in a combining action list.

I am trying to avoid of making of any scripts in my game and make everything mostly with action lists. So it will be great to hear your thoughts:

  1. The best solution is to block somehow the whole inventory while the document is opened. So basically I can combine items only in play mode. Is there a way of how I can do this?

  2. There is a way to close document from the combining action list every time when I combine this or that item. This will deactivate game pause and will start playing combining action list which is good for me! But the problem is that I can't find any function to close all documents at once. Any thoughts?

  3. Maybe there is an easy way of how I can block combination of items while document is opened and game is paused? This is also works for me.

Thanks,

Comments

  • Thank you, and yours.

    The best solution is to block somehow the whole inventory while the document is opened. So basically I can combine items only in play mode. Is there a way of how I can do this?

    The InventoryBox element's Prevent interactions? property can be used to block default click behaviour, and you can toggle this through script.

    Though you'd likely want to use an event of some kind, a quick-and-easy way to do this would be to place it in an Update function, i.e.:

    MenuInventoryBox inventoryBox;
    void Start ()
    {
        inventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventoryBox"); // Set menu / inventoryBox names here
    }
    
    void Update ()
    {
        if (KickStarter.stateHandler.IsPaused () && KickStarter.runtimeDocuments.ActiveDocument != null)
        {
            inventoryBox.preventInteractions = true;
        }
        else
        {
            inventoryBox.preventInteractions = false;
        }
    }
    

    Place that inside a new C# script, add "using AC;" at the top, and place it in your scene somewhere.

    There is a way to close document from the combining action list every time when I combine this or that item. This will deactivate game pause and will start playing combining action list which is good for me! But the problem is that I can't find any function to close all documents at once. Any thoughts?

    If a Menu is locked, it will turn off even if it's current Appear type condition is met. This can be done with the Menu: Change state Action, but also through custom script:

    void LockMultipleMenus ()
    {
        string[] menuNames = new string [3] { "Menu1", "Menu2", "Menu3" };
        foreach (string menuName in menuNames)
        {
            PlayerMenus.GetMenuWithName (menuName).isLocked = true;
        }
    }
    

    Such code could be incorporated into a custom Action, or simply placed on a prefab and triggered with the Object: Call event Action.

    Maybe there is an easy way of how I can block combination of items while document is opened and game is paused? This is also works for me.

    You can't block separate interaction types - just all or none. Probably best to go with the first method.

  • Thank you Chris, I'll try:)

  • edited April 2020

    Hey Chris, first scrip gives me error: Unexpected symbol `MenuInventoryBox'
    guess it's missing some symbol?

  • As with all custom scripts, be sure to include the AC namespace at the top of the script:

    using AC;
    
  • Yes, it's already there but it's still gives me this message.

  • Share the exact error message, and the exact script you're using - pasted into Paste ofCode.

  • https://paste.ofcode.org/Ydchyud5n6vDvd9NV82h8U

    Assets/Scripts/InventoryBox.cs(2,0): error CS1525: Unexpected symbol `MenuInventoryBox'

  • You need to paste the code inside the class - not replace it completely.

    e.g. If your file is named PauseInventory, this would be the contents:

    using AC;
    using UnityEngine;
    
    public class PauseInventory : MonoBehaviour
    {
    
        MenuInventoryBox inventoryBox;
        void Start ()
        {
            inventoryBox = PlayerMenus.GetElementWithName ("Inventory", "InventoryButton"); // Set menu / inventoryBox names here
        }
    
        void Update ()
        {
            if (KickStarter.stateHandler.IsPaused () && KickStarter.runtimeDocuments.ActiveDocument != null)
            {
                inventoryBox.preventInteractions = true;
            }
            else
            {
                inventoryBox.preventInteractions = false;
            }
        }
    
    }
    
  • edited April 2020

    Another error:
    Assets/Scripts/PauseInventory.cs(10,36): error CS0266: Cannot implicitly convert type AC.MenuElement' toAC.MenuInventoryBox'. An explicit conversion exists (are you missing a cast?)

  • Apologies.

    using AC;
    using UnityEngine;
    
    public class PauseInventory : MonoBehaviour
    {
    
        MenuInventoryBox inventoryBox;
        void Start ()
        {
            inventoryBox = PlayerMenus.GetElementWithName ("Inventory", "InventoryButton") as MenuInventoryBox; // Set menu / inventoryBox names here
        }
    
        void Update ()
        {
            if (KickStarter.stateHandler.IsPaused () && KickStarter.runtimeDocuments.ActiveDocument != null)
            {
                inventoryBox.preventInteractions = true;
            }
            else
            {
                inventoryBox.preventInteractions = false;
            }
        }
    
    }
    
  • As always, HUGE thank you Chris! It's working! I will test it with other scenes and will let you know if I will have any other issues:)

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.