Directions of Travel Commands to Actors

Hi! I’m using adv3lite. I have Actors who can be commanded to move in a specific direction.

modify Actor
    handleCommand(action) {
        if (action == Travel) {
            if (direction == north) {
                self.moveInto(self.location.north);
            } else if (direction == south) {
                self.moveInto(self.location.south);
            } else if (direction == east) {
                self.moveInto(self.location.east);
            } else if (direction == west) {
                self.moveInto(self.location.west);
            } else if (direction == up) {
                self.moveInto(self.location.up);
            } else if (direction == down) {
                self.moveInto(self.location.down);
            } else {
                inherited(action);
            }
            
        } else {
            inherited(action);
        }
    }
;

How exactly do I find the direction of the Travel command when it’s being used to command an Actor? direction doesn’t work, and dirMatch.dir throws a null reference error. Any help would be appreciated. Thanks!

2 Likes

Indirectly you noted a weak point in the excellent “Learning TADS3 with adv3Lite”: that chapters 14.11 (Giving orders to NPCs) and 14.12 (NPC travel) aren’t followed by their logical synthesis (that is, your very case, ordering NPC to travel), whose should be given, even I I’m not 100% sure on how to handle the complex case of giving a NPC follower the order to go into a direction (requiring stopFollowing, then moving in the ordered direction, I think, but never experimenting/fooling around this case)

Best regards from Italy,
dott. Piergiorgio.

1 Like

Hm, I would have to check out Lite, but in adv3 it requires no special coding to give travel commands as long as the Actor is set to obeyCommand…

Looking at your code:

if (action == Travel) {
            if (direction == north) {
                self.moveInto(self.location.north);
...

I think you want something closer to this:

if (action == Travel)
  if (action.direction == north)

However, Travel.direction doesn’t hold a Room location property, but rather a reference to a CompassDirection, e.g., northDir. So, I think this would be correct:

if (action == Travel)
  if (action.direction == northDir)

Each CompassDirection object holds a property pointer for the appropriate Room location property, such as:

northDir: CompassDirection
    dirProp = &north

So, I think your call could look something like this:

modify Actor
  handleCommand(action) {
    if (action == Travel) {
      self.moveInto(self.getOutermostRoom.(action.direction.dirProp));
    } else {
      inherited();
    }
  }
;

Unfortunately, I’m not in a place to fully debug the above. In particular, it needs to handle situations where the Room location property is nil, and moveInto() is probably not the best choice (travelVia() should be used for programmatic movement of Actors and vehicles).

But I think this will get you going in the right direction, with a few tweaks.

Also, you should check out the adv3Lite manual page on “Giving orders to NPCs.” I’m not fully familiar with this part of the library, but I think John’s right, there are ways to configure an Actor to follow the order without having to implement it. In particular, CommandTopics might be a better way to go here.

2 Likes