Forum rules - please read before posting.

Inventory - Subtitles when dragging & combining items

edited September 2021 in Technical Q&A

Hello,

It's been a long time since I've touched inventories in AC.

When the player clicks an item with the left mouse button, and then starts to drag it, I want to throw up some text at the bottom of the menu. If the player then drags the item over another, I want to complete the sentence.

Basically, I want some text appearing describing the interaction as it unfolds.

Here's a mock-up of what I want to achieve:

And here are my current inventory settings:

Can AC achieve this, or will it require custom scripting?

Comments

  • edited September 2021

    You'll need to use scripting, since your mockup effectively has two Hotspot labels - one under the cursor showing the item's name, the other for the "Combine X with Y" sentence.

    The "..." in this sentence that only shows when the cursor isn't over another item makes it the best candidate to be handled through script.

    Here's a function you can use to generate the mock-up sentence based on the selected inventory:

    public string GetCombineSentence ()
    {
        if (AC.KickStarter.runtimeInventory.SelectedItem != null)
        {
            string sentence = "Combine " + AC.KickStarter.runtimeInventory.SelectedItem.GetLabel (0) + " with";
            if (AC.KickStarter.runtimeInventory.hoverItem != null)
            {
                sentence += " " + AC.KickStarter.runtimeInventory.hoverItem.GetLabel (0);
            }
            else
            {
                sentence += "...";
            }
            return sentence;
        }
        return string.Empty;
    }
    

    This'll work for your game's default language, but can be adapted for translations without much hassle.

  • AC support at 8am on a Sunday. Chris, you wonderful wonderful person. I do hope you take days off.

  • Sorry Chris, I need to get better at scripting. I still trip over how to properly use AC stuff in script, however regarding that script you outlined, VS is saying:

  • Oh! Was it just a case of saying if (AC.KickStarter.runtimeInventory.SelectedItem != null)?

  • Quite right - I've corrected the above for future reference.

  • edited September 2021

    Works great. I added an extra check in the script so selected items can't be used with themselves.

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.