How do I check that there is no noun2?

This is one of those ‘probably blindingly obvious but…’ questions, so: how do I explicitly check that there is no noun2? What I am trying to do below is ‘talk to smith about [specific subject]’, if there is no noun2 then ask player what they want to talk about, otherwise noun2 must be unmatched so talk about the weather. But it doesn’t work. What am I missing?

start_at = my_location

locations {

   my_location : location "You are in a room." ;
   
}

on_command {
   
   : match "talk _"  {
      : if (noun1_is "smith") {
         : if (noun2_is "bacon") {
            : print "You chat to smith about bacon." ;
            
         }
         : else_if (noun2_is "grapes") {
            : print "You talk enthusiastically about grapes." ;
            
         }
         : else_if (noun2_is "") {
            : print "What do you want to talk about?" ;
            
         }
         
      : else {
         : print "You talk about the weather. This is England, after all!" ;
         
      }
      
         
         
      }
      
   }
   
}

I’m very likely not reading it right but but your code snippet seems to be working as expected for me. Maybe you can give me an input that you are typing in and an output you expect to see (but don’t), along with the explicit reason?

Well, the logic I am trying to get is:

  • match ‘talk to [noun1] about [noun2]’
  • if noun1 is ‘smith’ and noun2 ‘bacon’ then print the bacon response
  • if noun1 is ‘smith’ and noun 2 is ‘grapes’ then print the grapes response
  • if noun1 is ‘smith’ but there is no noun2 (eg noun2="") then print 'What do you want to talk about?" (I want this response if they player just enters ‘talk to smith’)
  • otherwise there must be a noun2 but it isn’t ‘bacon’ or ‘grapes’ so it must be something not explicitly matched, so print the vague weather response.

…but what happens is I get the 'What do you want to talk about?" reponse even if there is a noun2 but it is not one of the ones that I have specified, eg ‘talk to smith about puffins’, when what I want is the weather response.

I take it that ‘noun2_is “”’ is not equivalent to there being no noun2 (as I originally thought) but means any noun2. In which case, how do I check that there is definitely no noun2 and the player has just typed ‘talk to smith’ or ‘talk to smith about’?

Using the beta version, try this …

start_at = my_location

locations {

   my_location : location "You are in a room." ;
   
}

on_command {
   : match "talk _"  {
      : print {("\"" + experimental_parse_result_original "noun2" + "\"")}
      
      : if (noun1_is "smith") {
         : if (noun2_is "bacon") {
            : print "You chat to smith about bacon." ;
            
         }
         : else_if (noun2_is "grapes") {
            : print "You talk enthusiastically about grapes." ;
            
         }
         : else_if (experimental_parse_result_original "noun2" == "") {
            : print "What do you want to talk about?" ;
            
         }
         : else {
            : print "You talk about the weather. This is England, after all!" ;
         }
      }
   }
}

In the beta version, I added the following alias as a standard system alias.

“TALK TO” becomes “TALK”.

The problem before is that there were two prepositions. Adventuron doesn’t (yet) play well with multiple prepositions, but it can pre-process certain patterns.

e.g. “PICK UP” becomes “GET”
“PUT ON” becomes “WEAR”
and now
" TALK TO" becomes “TALK”

This will be configurable in future versions.

1 Like

That works, thanks.