WAITFOR
Syntax: #WAITFOR {pattern} timeout {match-commands} {timeout-commands}
Suspends the current thread and waits for a line from the server that matches the specified pattern. If timeout is specified, it indicates the number of milliseconds to wait before giving up. If the timeout expires, the rest of the thread's script is aborted.
The match-commands and timeout-commands are optional command blocks that should be executed when the pattern is received, or when the timeout occurs. If these are omitted, then the script will continue with the next statement when the pattern is received, and will exit the script if a timeout occurs.
NOTE: Normally it is better to create a trigger that fires when a pattern is received from the MUD. Using WAITFOR will suspend the current thread and will cause parallel threads to be running at the same time. For complicated scripts, using triggers can prevent thread synchronization problems. So WAITFOR should only be used for simple scripts that do not access any global resources.
WAITFOR example
#WAITFOR {^Username:}
#CHAR
#WAITFOR {^Password:} 1000
#PW
Waits for the string "Username:" to be sent at the beginning of a line, and then sends the user's character name, then waits one second for the server to send the "Password:" string, and then sends the user's password back to the server.
#ALIAS recall {
#SEND recall
#WAITFOR {The Temple Square} 3000 {#RECALL} {#SAY Recall failed!}
}
In this example, we create an alias for the "recall" command. It sends "recall" to the MUD, then waits to see the name of the room that we are recalling to. If the room name is received within 3 seconds, then we use the #RECALL command to update the mapper position. Otherwise the mapper position is not updated and we display "Recall failed!" to the screen. |