SYNOPSIS

int notify_fail( string str)
int notify_fail( closure cl)

DESCRIPTION

Store str as the error message given instead of the default message “What ?”. The result is always 0.

If a closure is given, it is executed to return the error message string, but not before all attempts to execute the commandline failed (read: not at the time of the call to notify_fail(E)). The closure receives as argument the original commandgiver; usually it is identical to this_player(), unless H_MODIFY_COMMAND(H) changed that.

If notify_fail(E) is called more than once for this command, only the last call will be used. However, calls to notify_fail(E) in nested commands have no effect on this command.

USAGE

The idea of this function is to give better error messages instead of simply ‘What ?’.

A naive to write a message when a simple command fails is:

write(message);
return 1;

Unfortunately, this message will print before other objects get a chance to evaluate the verb. It is better to use:

return notify_fail(message);

This way, the driver only prints a single failure message–and only if the verb fails all of the objects that get a chance to handle it.

HISTORY

  • changed (3.2.6) – return type from void to int.
  • changed (3.2.7) – notify-fail settings are saved over nested commands, and NPCs can see their notify-fail messages.