Converting a Literal Object to an Object Match

So I have the action SetTo being called, which has the following rule:

'set' singleDobj 'to' literalIobj

Is there a way of taking the content of literalIobj and trying to match it to an iobj?
Like, if the literalIobj contained the token “station”, could I replace it with another action,
and attempt to find an iobj which has a vocab match for “station”?

Hypothetically, like so:

// These methods are all fictional, btw
local literalTokens = getTokensFromLiteral(gLiteralIobj);
gCommand.remapTokensToObj(literalTokens, IndirectObject);
doInstead(OtherActionName, gDobj, gIobj);

Is this possible?

Thank you for your time!

1 Like

I think I could get a handle on that in adv3, but I’ll wait and see if any Lite users know that right off, because most of Lite under the hood is still unknown to me…

1 Like

For what it’s worth, I got my special case working by changing the badness rating of SetTo.

However, even if I found my solution, this is not going to be viable for most future explorers who have this problem. I just happened to have a special case.

So I’m leaving the question marked “unsolved” for now, unless someone confirms that this simply is not possible, in a general case.

1 Like

One brute force way of doing it would be to use gLiteral (the string value of the literalIobj) to construct a new command and then force the parser to parse (and run) the new command, e.g., the following would take a command like SET WIDGET TO FOO and turn it into PUT WIDGET ON FOO:

widget: Thing 'widget'
    dobjFor(SetTo)
    {
        verify() { }
        
        action()
        {
            local str = 'PUT <<name>> ON <<gLiteral>> ';
            Parser.parse(str);                
        }        
    }    
;

A more rigorous alternative would be to define a TopicTAction version of SetTo with the appropriate grammar (using topicIobj in place of literalIobj in the corresponding verbRule) and then inspecting the value of gTopicMatch to see if it’s a Thing or a Topic. If it turns out to be a Thing you could then use:

If(gTopicMatch.ofKind(Thing))
      doInstead(OtherActionName, gDobj, gTopicMatch);
else
     /* Do something with gTopicText, the text entered by the player */
3 Likes