Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to handle generic nouns in on_command{}

A topic by Garry Francis created Sep 04, 2019 Views: 138 Replies: 7
Viewing posts 1 to 7
Submitted

I want to do something like this:

: match "give _" {

   : if (is_carried "_") {

      : print "He says, \"Thanks, but I have no use for that.\";

   }

}

In other words, for whatever object is specified in the input, I need to be able to check if it's carried. There are dozens of other situations where this sort of situation occurs. How do I refer to the generic noun in the subsequent tests where I've used "_"?

I'm not completely sure what you want to do.

You'd presumably want to code a response for each object anyway, as he'll presumably want some and not the others .

Is this what you're after? You can nest the match commands like this...

   : match "give _" {
      : match "_ banana" {
         : if (is_carried "banana") {
         : print "You give him the banana.";
         // set appropriate boolean, destroy banana etc.
         : done;}}
      : match "_ box" {
         : if (is_carried "box") {
         : print "He doesn't want that.";
         : done;}}
      : print "You don't have that to give him.";
      : done;}

Obviously you'd need to add extra checks to the code, to check the NPC was there.

Submitted

The preceding underscore is a useful trick. I didn't know you could do that. But it doesn't solve the problem. If I say GIVE TREE, I don't want to have to check every single object to see whether it's carried before giving the rejection message.

Submitted

Perhaps I should have mentioned that I'm already doing the explicit :match "verb noun" {} before handling the generic case. I don't want to say "You don't have that to give him." when I actually DO have it and I don't want to say "He doesn't want that." when the thing doesn't even exist.

I think you're getting too complicated. It's not unusual for an 8-bit-style game to just have a general "He doesn't want that" as a catch-all for generic cases, which doesn't perform a carried check.

I can understand why that might not be the solution you're after. For me, part of the fun would be writing amusing rejection responses for each item. 

Submitted

I suppose I'm thinking ahead. If I was to use Adventuron to write a real game in future, I would certainly want this. Even in the small CaveJam game, I'm getting some silly responses. Call me a perfectionist, but I don't like silly responses.

Host

Unfortunately I can't add features as fast as you ask for them. This particular feature is not something I had not considered, and indeed, it is something that I intended to add at some point, so it's nice in a way to have someone confirm that it is useful.

For this jam however, 8BitTag's workaround is the best way.