Usage:
/REPEAT [-w[world]]
[-n] {[-time]|-S|-P} count command
Repeats command, count times. Command may be any
legal macro body. If count
is "i
", the command repeats indefinitely.
This works through a process,
which runs concurrently with normal operations.
The command undergoes macro body substitution when it is executed.
An asynchronous /repeat (without -S) returns the pid of the new process, or 0 if an error occurred. A synchronous /repeat returns the return value of the last command.
Since the first run is not done until after the first interval (for /repeat without -S or -n), a useful trick is to use "/repeat -time 1 command" to delay the execution of a single command.
Example: /repeat -0:30 1
/echo -ab Dinner's ready
There is no good way to directly "sleep" within a macro body. Any attempt to write your own /sleep macro will, at best, "freeze" tf for the duration of the sleep, or even worse hog the machine's CPU time in a busy wait. The best way to achieve the effect a sleep in a /while loop is probably to use a /repeat where each execution of the /repeat body corresponds to an iteration of the desired /while loop. That is, if you want to write
/def foo = \ /before_stuff%; \ /while (condition) \ /do_stuff%; \ /sleep 5%; \ /done%; \ /after_stuffyou must instead write:
/def foo = \ /before_stuff%; \ /foo_loop /def foo_loop = \ /if (condition) \ /do_stuff%; \ /repeat -5 1 /foo_loop%; \ /else /after_stuff%; \ /endifOf course, local variables will not survive between calls of /do_stuff in the second version as they would in the first (if it were possible), so any variables you need to share between iterations must be global.
But, if the reason you want to sleep is to wait for a response from a server, then you really don't want to sleep at all: you want a trigger. First, set up triggers on the possible responses, then send the command. If one of the possible responses is no response at all, then a /repeat can be useful to wait for some maximum timeout and then handle the no-reponse case and delete the response triggers. This is in general the best way to write macros that interact with a server.
See: processes, %ptime, /at, kbnum