[Adventuron] - 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.

I’m having trouble with this pattern again. The solution above no longer works as
experimental_parse_result_original is no longer recognised in the beta version. How do I distinguish between there being a noun2 that I haven’t matched and there being no noun2 at all?

eg in the below, respond to filling the bucket with water or champagne. If neither of those (but something else), ‘you can’t fill the bucket with that’. If no noun2 at all then: ‘what do you want to fill the bucket with?’

start_at = my_location

locations {

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

on_command {
   : match "fill bucket"  {
    : if (noun2_is "water") {
       : print "You fill the bucket with water." ;
    }
        : else_if (noun2_is "champagne") {
       : print "You fill the bucket with champagne and settle down to breakfast." ;
    
    }
    
    : else_if (noun2_is "") {
       : print "What do you want to fill the bucket with?" ;
       
    }
    : else {
       : print "You can't fill the bucket with that!" ;
       
    }
    
    
    
    
      
     }
     }

original “noun2” == “”

Apologies if I’m misunderstanding, but that doesn’t make any difference for me:

>FILL BUCKET WITH WATER
 You fill the bucket with water.

>FILL BUCKET WITH CHAMPAGNE
You fill the bucket with champagne and settle down to breakfast.

>FILL BUCKET WITH HELICOPTERS
What do you want to fill the bucket with? *I want this to be 'You can't fill the bucket with that!'

>FILL BUCKET
What do you want to fill the bucket with?
start_at = my_location

locations {

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

on_command {
   : match "fill bucket"  {
    : if (noun2_is "water") {
       : print "You fill the bucket with water." ;
    }
        : else_if (noun2_is "champagne") {
       : print "You fill the bucket with champagne and settle down to breakfast." ;
    
    }
    
    : else_if (original "noun2" =="") {
       : print "What do you want to fill the bucket with?" ;
       
    }
    : else {
       : print "You can't fill the bucket with that!" ;
       
    }
    
    
    
    
      
     }
     }

`

Ah, it seems that “with” wasn’t a standard preposition for Adventuron, I’ve updated the code to add this in.

In the meantime, adding this will identify “with” as a preposition, which will let Adventuron understand that HELICOPTERS is noun2.

vocabulary {
   : preposition {
      aliases = [with]
   }
}

Great, that works. Thanks Chris.

When strange things are happening with the parser, try inserting the chunk of code I gave in this thread at the beginning of the on_command section. In this way, you can see what Adventuron has thrown away and what it considers to be preposition, noun1 and noun2.

As a general rule, always define your prepositions in the vocabulary section so that it knows to treat them as prepositions, otherwise it will think they are noun1 or noun2 and your tests on those will be screwed up.

Got it, thanks Garry.

Incidentally, after adding ‘with’ to the prepositions as Chris advised, you can leave the original code as noun2_is "" and it will work.