Getting exact synonym used. TADS3

I’m trying to get at the exact synonym that a player used in a commend.

Consider an object that has many parts and you want to know if a player has referred to a particular part.

Or a collective object like “paintings” in a gallery that you want to use to handle multiple verbs like take, destroy, etc, but which you want to respond with a few specifics if you refer to the Rembrandt or the Degas.

getEnteredVerbPhrase will tell me which verb a player used. e.g. ‘examine (dobj)’

gAction.getOrigText will get me the entire original command word for word, but it is tedious to check for every literal input. e.g.

            if ((gAction.getOrigText() == 'examine rembrandt') ||
                (gAction.getOrigText() == 'examine the rembrandt') ||                 
                (gAction.getOrigText() == 'look at rembrandt') || 
                (gAction.getOrigText() == 'look at the rembrandt') ||
                (gAction.getOrigText() == 'x rembrandt') || 
                (gAction.getOrigText() == 'x the rembrandt')) {
                "The Rembrandt looks beautiful. ";

There is something called getNounText, but I can’t figure out what it returns and how to test it.

Any ideas?


Not sure how to get the exact word the player used, but your idea of doing it can be simplified greatly by simply checking if getOrigText() contains the word in question:

if (gAction.getOrigText().find('rembrandt')) { "The Rembrandt looks beautiful. "; }
You would use that in the “examine” handler for the collective.

Wow, this works perfectly! I spent so much time on this - I keep forgetting how great this forum is.

Thank you!


I don’t remember if this kind of text search is case-sensitive though. Make sure to check lower and upper case.

Manual doesn’t seem to mention this explicitly, but yes, find() is case sensitive. And regular expression searches are also case sensitive by default, but can be switched to case insensitive by nocase tag:

if(gAction.getOrigText().find(R'<nocase>rembrandt')) { ... }

Although find() is mainly used to plain text searches, it can do regular expression search. But more traditional way doing the same would be:

if(rexSearch(R'<nocase>rembrandt', gAction.getOrigText())) { ... }

R’some string’ is an shorthand for static regular expression, ie. pattern = static new RexPattern(‘some string’).

I don’t know why find() can’t be made case insensitive, maybe it is meant as simple speedy search function, but given that yet another way:

if(gAction.getOrigText().toLower().find('rembrandt')) { ... }