Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 1 | SYNOPSIS |
| 2 | int notify_fail(string str) |
| 3 | int notify_fail(closure cl) |
| 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 5 | DESCRIPTION |
| 6 | Store str as the error message given instead of the default |
| 7 | message ``What ?''. The result is always 0. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 8 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 9 | If a closure is given, it is executed to return the error |
| 10 | message string, but not before all attempts to execute the |
| 11 | commandline failed (read: not at the time of the call to |
| 12 | notify_fail()). The closure receives as argument the original |
| 13 | commandgiver; usually it is identical to this_player(), unless |
| 14 | the modify_cmd hook changed that. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 15 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 16 | If notify_fail() is called more than once for this command, only the |
| 17 | last call will be used. However, calls to notify_fail() in nested |
| 18 | commands have no effect on this command. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 20 | The idea of this function is to give better error messages |
| 21 | instead of simply 'What ?'. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 23 | It is also better to use |
Zesstra | 5481d49 | 2021-04-08 20:07:06 +0200 | [diff] [blame] | 24 | notify_fail(message); return 0; |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 25 | instead of |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 26 | write(message); return 1; |
| 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 28 | Other objects will get the chance to evaluate the verb. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 29 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 30 | HISTORY |
| 31 | Returntype changed in LDMud 3.2.6 from void to int. |
| 32 | Since LDMud 3.2.7, notify-fail settings are saved over nested |
| 33 | commands, and NPCs can see their notify-fail messages. |
| 34 | |
| 35 | |
| 36 | SEE ALSO |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 37 | add_action(E), command(E), query_verb(E), query_command(E), |
| 38 | query_notify_fail(E), hooks(C) |