How to Match when an object can be noun1 or noun2

Hello! I have a question!
I have an all-purpose tool, a crowbar. I would like to catch:
use crowbar on *” as well as “break * with crowbar

The * is either noun1 or noun2. So I can’t make one match statement to match both (from what I can tell).

Normally, I would do this with two or more match statements, and then use “set_sentence” so I don’t have to type out code twice. However, that works if I know the nouns (or verb) and can type them out.

But if it’s a *, I can’t do that. And I don’t think I can use set_sentence with a dynamic string.

Does that make sense? (And I could also be doing things complicated this whole time)

Is there a better solution to catch both

Use crowbar on *
and
Break * with crowbar
(or open, pry, pull, which are their own verbs in their own right)

(NOTE: I’ve just documented this in the user guide, for anyone having this issue in the future).

Assigning a common action to completely different patterns of text is a known weakness in Adventuron.

A completely different (and recommended) approach to matching in a later release (whilst maintaining the current method).

The new method would define actions in relation to patterns of text, direct object, and indirect object, as well as describing where to look for objects in the text pattern slots, and how to imply objects where it makes sense such that verb noun may be used as a shortform.

With all of that said, sentence re-writing is possible with Adventuron, using the set_sentence command and $1 and $2 special values (subject1 and subject2). $1 will substitute in adjective1 (if supplied) and noun1 (if supplied). $2 will substitute in adjective2 (if supplied) and noun2 (if supplied).

: set_sentence "break $2 on $1";

I’m not defending the current matching system as it will will be replaced, but as of today, here is a more complete code sample that should solve your issues:

To build on this, you may wish to assign certain objects with certain default actions and place those objects into an if then else loop, and change the substitution verb depending on the object. Feel free to incorporate this snippet into your own code.

###################################
## Sentence re-writing
####################################
## use crowbar on lock <--> break lock with crowbar
####################################

start_at = cell

locations {
   cell : location "You are in your cell." ;
}

objects {
   crowbar : object "a crowbar" at = "inventory" ;
   lock    : scenery "a lock" at = "cell" ;
}

on_command {
   : gosub "sentence_rewriting";
   : match "break _"  {
      : if (subject1_is "lock" && subject2_is "crowbar") {
         : if (is_carried "crowbar") {
            : print "You try to break the lock with the crowbar, but it is solid." ;
         }
         : else {
            : print "You don't have it." ;
         }
      }
   }
}

subroutines {
   // NOTE :: Never print anything in the sentence re-writer, as this will override the system command handler.
   sentence_rewriting : subroutine {
      : if (verb_is "use") {
         : if (original "noun2" != "") {
            : if (subject1_is "crowbar" && (preposition_is "on" || preposition_is "with")) {
               : set_sentence "break $2 with $1" ;
            }
         }
         : else {
            : if (original "noun1" == "") {
               : print "Use what on what?";
            }
            : else {
               : print {("Use " + original "noun1" + " " + (original "preposition" == "" ? "on" : original "preposition") + " what?" )}
            }
         }
      }
   }
}

Oh wow! That’s amazing! Thank you so much! That will help me with a number of matches I needed!

You failed to mention that the placement of the set_sentence statement is extremely important. If you have two match statements, the set_sentence must be placed after the first one, otherwise the changed sentence doesn’t get processed.

For example, assume I want GIVE SEED and FEED BIRD to be synonymous. Try this (changes in object state omitted for simplicity):

: match "give seed" {
   : print "You give the seed to the bird.";
   : done;
}
: match "feed bird" {
   : print "You feed the bird with the seed.";
   : set_sentence "give seed";
}

If I enter GIVE SEED, the first response is printed and everything is fine.

If I enter FEED BIRD, I would expect the second response to be printed, the sentence changed, then the first response printed, but that doesn’t happen. It only prints the second response. It does not go back to the beginning after the sentence is changed.

If I swap the two match statements, then it works as expected. The bottom line is that the set_sentence statement must be associated with the first match statement, not the second.

I hope I made that clear.