Forum rules - please read before posting.

Use and Examine in the same button & Checking password

Hello,

My game setting are Direct input with keyboard only and hotspot detection method with player vicinity nearest only. I have two questions:

1) I want to set Use and Examine of Inventory's standard interactions in the same keyboard button, because my items only have functions Use or Examine. For example, a map is only for viewing when the player presses a button and it will show the menu that appears a big map on the screen. I have already done this menu. ¿How can I set Use and Examine in the same keyboard button?

2) I have an input menu that the player needs to insert a password to open the case, but I don't have some button like Ok to check the password, so I want to check the password until the password is correct when the player opens that menu.

Regards,
Lrei

Comments

  • How can I set Use and Examine in the same keyboard button?

    Inventory items can be interacted with via inputs named InteractionA and InteractionB. These can be mapped to the same input button in Unity's Input Manager, but you can also use a script to merge them only while e.g. your Inventory menu is open - so that you can keep them as separate buttons at other times.

    Let me know if that's the right approach for you, I'll help with a sample script.

    I want to check the password until the password is correct when the player opens that menu

    You can either run a looping ActionList that updates a Variable based on the Input element's contents and checks it, or read its contents directly through script:

    string contents = (PlayerMenus.GetMenuWithName ("MyMenu", "MyInputElement") as MenuInput).GetContents ();
    if (contents == "CorrectPassword")
    {
        // Password is correct
    }
    

    Again, let me know your preferred approach and I can advise further.

  • Let me know if that's the right approach for you, I'll help with a sample script.

    Yes, that is what I want, but I tried setting the same input button in Unity Input Manager, but only the first time I opened the map was successful appearing a big map on the screen, after I closed that, I can't reopen it no matter how I press after the first time. But it didn't happen when the InteractionA and InteractionB are separated.
    Does the same input button in Unity's Input Manager cause a conflict? I also use the script of last time that I ask to make when the player is near a hotspot, then using the item will run Hotspot/Inventory interaction. Does it affect this?
    In the standard interactions section of the item 'map', I only have interaction in the Examine, nothing in the Use.

    Again, let me know your preferred approach and I can advise further.

    In the script, how can I loop to update variable based on the Input element's?

  • edited April 2021

    In the standard interactions section of the item 'map', I only have interaction in the Examine, nothing in the Use.

    If you assign the Examine ActionList in the Use slot as well, then either input should trigger it.

    Alternatively, this script will cause InteractionA inputs to refer to InteractionB while the menu "Inventory" is open:

    using UnityEngine;
    using AC;
    
    public class MergeInventoryInputs : MonoBehaviour
    {
    
        void Start ()
        {
            KickStarter.playerInput.InputGetButtonDelegate = CustomGetButtonDown;
        }
    
        private bool CustomGetButtonDown (string buttonName)
        {
            if (buttonName == "InteractionA" && PlayerMenus.GetMenuWithName ("Inventory").IsOn ())
            {
                return Input.GetButtonDown ("InteractionB");
            }
            try
            {
                return Input.GetButtonDown (buttonName);
            }
            catch {}
            return false;
        }
    
    }
    

    how can I loop to update variable based on the Input element's?

    If you have a Global String variable named "InputText", you can update it with:

    GlobalVariables.GetVariable ("InputText").TextValue = contents;
    
  • edited April 2021

    If you assign the Examine ActionList in the Use slot as well, then either input should trigger it.

    I set an actionlist in both Examine and Use slots, it also doesn't work when I want to press either input the second time. It is the same problem as before when I press input for the first time, it works, but after that, it doesn't work no matter how many times I press.

    I have items of inventory that it can use for hotspots when the player is near them, or items like map if the player presses the interaction button, it appears on a big map on the screen.

    Another problem that I found is that after the first time I opened the item map, when I was near the hotspot and I pressed another item to interact, it didn't work.

  • I'm sorry, but I'll need more detail in terms of what exactly happens when clicking an item. Can you share screenshots?

    It is the same problem as before when I press input for the first time, it works, but after that, it doesn't work no matter how many times I press.

    So inventory items can only be interacted with once? Is this true no matter what the Action is? For example, if you create a new ActionList asset with a single Dialogue: Play speech Action and assign this as the item's Examine interaction, are you only able to examine it (and play the dialogue) once?

    If so, what is the state of your AC Status box at this time? You can enable it from the bottom of the Settings Manager.

    Another problem that I found is that after the first time I opened the item map, when I was near the hotspot and I pressed another item to interact, it didn't work.

    Is this a menu that pauses the game, and is it still open at the time the interaction won't run? Again, I think I need to see some screenshots to understand the situation - please share as much as you can.

  • edited April 2021

    are you only able to examine it (and play the dialogue) once?

    If I set InteractionA and InteractionB in different buttons, it can examine every time when I press the Interaction button. But if I set InteractionA and InteractionB in the same button, it can only examine at first time.
    When the actionlist runs, the state is pause, after that, it is normal.

    Is this a menu that pauses the game, and is it still open at the time the interaction won't run?

    It seems when the interaction doesn't run, the menu will close.

    Here are some screenshots of my setting and a small video record that shows for the first time, I could use the item to interact when I am near the hotspot. Then, in the second play, I pressed interaction button (InteractionA and InteractionB in the same button) to open the menu that show a paper, after that I was trying press the that item, but it didn't appear the menu, and also it didn't work for other item when I was near the hotspot.

    https://drive.google.com/file/d/11XvdwxqkNo2mKwyXZ9e4Vmup6QyeEcvV/view?usp=sharing
    https://drive.google.com/file/d/1Z0LlyG89kI8FTeVJk4oEapadzn4mdMBp/view?usp=sharing
    https://drive.google.com/file/d/10jTvjZiK6kY66Lce1fW1iRdE5hDSYH8C/view?usp=sharing
    https://drive.google.com/file/d/1_ElB7P68EQVXVXiYslT8a1vFFKof9axF/view?usp=sharing

    I use this code to interact item with hotspot.

    using UnityEngine;
    using AC;
    
    public class AutoUseItemOnHotspot : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnInventorySelect += OnInventorySelect; }
        private void OnDisable () { EventManager.OnInventorySelect += OnInventorySelect; }
    
        private void OnInventorySelect (InvItem invItem)
        {
            if (KickStarter.player.hotspotDetector.NearestHotspot)
            {
                PlayerMenus.GetMenuWithName ("Inventory").TurnOff ();
                KickStarter.player.hotspotDetector.NearestHotspot.RunInventoryInteraction (invItem);
            }
        }
    
    }
    
    
  • Your OnDisable function needs to un-register the event:

    private void OnDisable () { EventManager.OnInventorySelect -= OnInventorySelect; }
    

    As an alternative to mapping both InteractionA and InteractionB to the same button, have you tried the MergeInventoryInputs script in my second reply?

  • Your OnDisable function needs to un-register the event:

    I changed, but nothing changed.

    I also tried the MergeInventoryInputs script, but nothing changed too.

  • Are you using any other custom scripts?

    The MergeInventoryInputs script will only work for AC menus - is yours Unity UI, and is it named "Inventory"?

    I don't have enough detail to diagnose the issue. If you can PM me a project/package with instructions on how to recreate the problem, I can take a look.

  • I have solved my issue, I think it is problem with active inputs that I set the active input to the same button with InteractionA and InteractionB.

    Thanks for all, Chris, you are very kind.

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.