NPC following Player?

Hi! I am trying to have an NPC follow the player, and I realized I don’t know how to order an NPC to perform an action, either in general or, for example, moving in a direction. Here’s what I have so far:

(on every tick in *)
    (#player is #in $room1)
    ~(#npc is #in $room1)
    (#npc is #in $room2)
    (shortest path from $room2 to $room1 is $path)
    ([$step | $] = $path)
    %% What now?

I’d love to know how to make this work!

Hi!

NPC movement is one of the things the standard library doesn’t do yet; it’s on my list. But let’s improvise a quick solution. First step is to convert the compass direction, $step, into a room:

        (from $room2 go $step to room $nextroom)

Note “to room”, which will handle redirections and doors. We can assume that this query succeeds, because we got the compass direction from the path finder.

Since the NPC is always moving towards the PC in this example, we only need to narrate their entrance. So, first we move the NPC. Then, if they moved into the room with us, we mention that.

        (now) (#npc is #in $nextroom)
        ($nextroom = $room1) %% either gate it like this, or use an if-statement
        (The #npc) enters
        (if) (from $room1 go $narrateDir to $room2) (then)
                from the (name $narrateDir)
        (endif)
        .

The bit with $narrateDir doesn’t deal with doors, and could print e.g. “from the up”, which is sloppy coding. But it could be a starting point.

2 Likes

Thank you so much for the quick response! This should work for my needs just fine. Appreciate all the hard work you’ve put in to Dialog!

1 Like