Speed Is On Your Side
Another use of exp_continue appears in the robohunt script that comes with Expect as an example. robohunt automates the game of hunt. Unlike the rogue script mentioned earlier, robohunt plays the whole game for you. hunt is a character graphics game that lets you navigate through a maze. You attack other players or crash through walls simply by moving into them. Certain walls cannot be broken through. If you try to do so, the game responds by ringing the bell, done by sending a ^G.
The other details of the game or script are not important except for one aspect. The script works by precalculating a number of moves and sending each batch of moves out at once. The script uses a crude heuristic for deciding which way to move, so it occasionally runs into a wall and keeps running into a wall for the rest of the batch of moves. This causes the game to send back a whole slew of ^G’s. The script handles it with the following command:
set bell "\007"
expect {
-re "^$bell+" exp_continue
-re "again\\? " {send y}
-re ".+"
}
The first pattern checks if the output starts out with a sequence of ^G’s (here denoted by "\007“). If the ^G’s are found, they are matched and effectively discarded as the action simply restarts the expect command.
If the script’s player is killed, the game stops and asks "Do you want to play again?“. It suffices to check for the final question mark and space, but this would leave the script with a fairly cryptic pattern. Adding "again" to the pattern ...