/IF (expr) list [ /ELSEIF (expr) list ]... [ /ELSE list ] /ENDIF
/IF list /THEN list [ /ELSEIF list /THEN list ]... [ /ELSE list ] /ENDIF

List is any list of commands. The return value of a list is the return value of the last command executed in the list. Note that each list must be terminated by "%;".

expr is any expression, and must be surrounded by parentheses.

The list or expr following the /IF is executed or evaluated. If the result is non-zero, the next list is executed. Otherwise, this is repeated for each /ELSEIF. If none of the /IF or /ELSEIF lists or exprs return non-zero, the /ELSE list is executed if there is one.

The return value of the /IF.../ENDIF statement is the return value of the last expr evaluated or list executed.

/IF (expr) body%; /ENDIF
is equivalent to
/IF /TEST expr%; /THEN body%; /ENDIF
except that in the former, expr does not undergo macro body substitution.

When /IF is used on the command line, "%;" command separation is done even if %sub=off. Of course, full substitution will be done if %sub=full.

If list is a server (mud) command, the condition being tested is whether the command is sent successfully; that is, whether there is a current socket. TF has no way of knowing how the server deals with the command or what is considered "success" for a server command, and tf does not wait for a server response which will be delayed by network latency. So, doing something like "/if rob corpse%; /then ..." will not have the effect you probably want. To achieve that effect, you should define a trigger on each of the possible server responses, before you send your command.


  /if (TERM !~ "dumb") /visual on%; /endif
will do "/visual on" if your %{TERM} is not "dumb".

See: evaluation, expressions, /test, /def -E,

Back to index
Back to tf home page
Copyright © 1995 - 1999 Ken Keys