Forum rules - please read before posting.

Add a Text Parser System ?

Good morning,

I had an idea for a game with an Text Parser System like the old Sierra games.
Can this be added in the future?
Or is this too difficult to do?

Comments

  • It would be possible with a custom interaction system - see the Manual's "Custom interaction systems" chapter for details on how these are generally implemented.

    Essentially, a script would scan the entered text for verbs, listed in the Cursor Manager, as well as Hotspots present in the scene, and then run the appropriate interaction.

    I'll see if I can whip up an example script.

  • I'll see if this can be conveted into a package on the Downloads page in the future, but for now: here's a bare-bones function that'll parse some text and attempt to run the correct Hotspot / Inventory interaction:

    void ParseText (string text)
    {
        if (string.IsNullOrEmpty (text)) return;
    
        text = text.ToLower ();
        int languageIndex = Options.GetLanguage ();
    
        // Detect verb
        int verbID = -1;
        int verbIndex = -1;
        foreach (var icon in KickStarter.cursorManager.cursorIcons)
        {
            string iconLabel = icon.GetLabel (Options.GetLanguage ());
            int _verbIndex = text.IndexOf (iconLabel.ToLower ());
    
            if (_verbIndex >= 0)
            {
                verbIndex = _verbIndex;
                verbID = icon.id;
                break;
            }
        }
    
        // Detect inventory item
        string useItemPrefix = KickStarter.runtimeLanguages.GetTranslation (KickStarter.cursorManager.hotspotPrefix1.label, KickStarter.cursorManager.hotspotPrefix1.lineID, languageIndex).ToLower ();
        string giveItemPrefix = KickStarter.runtimeLanguages.GetTranslation (KickStarter.cursorManager.hotspotPrefix3.label, KickStarter.cursorManager.hotspotPrefix3.lineID, languageIndex).ToLower ();
    
        InvInstance invInstance = null;
        foreach (InvInstance _invInstance in KickStarter.runtimeInventory.PlayerInvCollection.InvInstances)
        {
            if (text.IndexOf (_invInstance.ItemLabel) > 0)
            {
                invInstance = _invInstance;
                break;
            }
        }
    
        // Detect Hotspot
        Hotspot hotspot = null;
        foreach (Hotspot _hotspot in KickStarter.stateHandler.Hotspots)
        {
            string hotspotLabel = _hotspot.GetName (Options.GetLanguage ());
            int hotspotIndex = text.IndexOf (hotspotLabel.ToLower ());
    
            if (hotspotIndex > 0 && HotspotIsValid (_hotspot))
            {
                hotspot = _hotspot;
                break;
            }
        }
    
        // Item / Hotspot combine
        if (InvInstance.IsValid (invInstance) && hotspot && (text.IndexOf (useItemPrefix) >= 0 || text.IndexOf (giveItemPrefix) >= 0))
        {
            var interaction = hotspot.GetInvButton (invInstance.ItemID);
            if (interaction != null && !interaction.isDisabled)
            {
                hotspot.RunInventoryInteraction (invInstance.ItemID);
                return;
            }
        }
    
        // Item interaction
        if (InvInstance.IsValid (invInstance) && verbID >= 0)
        {
            foreach (var interaction in invInstance.Interactions)
            {
                if (interaction.icon.id == verbID && interaction.actionList)
                {
                    interaction.actionList.Interact ();
                    return;
                }
            }
        }
    
        // Hotspot interaction
        if (hotspot && verbID >= 0)
        {
            var interaction = hotspot.GetUseButton (verbID);
            if (interaction != null && !interaction.isDisabled)
            {
                hotspot.RunUseInteraction (verbID);
                return;
            }
        }
    }
    

    This searches the text for verbs listed in the Cursor Manager, and Hotspots in the scene / Items being carried. For example, "Look at chair" will work if a Hotspot named "Chair" has a "Look at" interaction.

  • I've expanded upon this and added it as an official template to the Downloads page.

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.