It would be more useful to see your code, rather than the code from "Learning TADS 3," as I have a copy of that already.
From your description of the edits you've made in that code, I don't understand how your edits relate to the design concept you initially set forth. For instance, "then back into nil with the PC following." Surely that's not what you meant to say. I'm also wondering what happens if the player follows the NPC back and forth through rooms 1 to 4, but then does not follow the NPC into room 5 to observe what happens there. Won't the whole cycle need to be repeated until the PC gets the right idea?
Puzzle design is sometimes a compromise between our original, more literary vision of the scene on the one hand and, on the other hand, what it's practical to code. If you want the player to follow the NPC into room 5, you might be better advised simply to put room 5 on the NPC's route list.
With respect to your idea of having the NPC go up and down through rooms 1, 2, 3, 4, 3, 2, 1, etc., you'll need to do more than reset idx. Think about the logic. You need a separate, persistent variable (one that's not local to the method -- let's call it wanderDirection, and let's say it's either 1 or -1) to keep track of whether the NPC is progressing upward through the room list (1-2-3-4) or downward (4-3-2-1). If wanderDirection is 1 and idx is room 4, then you first need to switch the wanderDirection to -1. And conversely. If wanderDirection is -1 and idx is room 1, you need to switch wanderDirection to 1. You would then add the value of wanderDirection:
Code:
idx = idx + wanderDirection;
local dest = routeList[idx];
...and so forth. That should cause the NPC to pace back and forth. As far as getting him to go to room 5 with a fuse? I don't know. Everything depends on how you've set it up.