From 0aebbf69752f89b25aaddaf53c7754d8eb8d0bf1 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 21 Jan 2017 22:59:43 +0100 Subject: [PATCH] Make evmenu 'goto' option argument accept a callable for deciding the next node. --- evennia/utils/evmenu.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index 306c5e21b4..b0a2c5fc07 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -785,12 +785,24 @@ class EvMenu(object): Run a node by name Args: - nodename (str): Name of node. + nodename (str or callable): Name of node or a callable + to be called as `function(caller, raw_string)` or `function(caller)` + to return the actual goto string. raw_string (str): The raw default string entered on the previous node (only used if the node accepts it as an argument) """ + if callable(nodename): + try: + if len(getargspec(nodename).args) > 1: + # callable accepting raw_string + nodename = nodename(self.caller, raw_string) + else: + nodename = nodename(self.caller) + except Exception: + self.caller.msg(_ERR_GENERAL.format(nodename=nodename), self._session) + raise try: # execute the node, make use of the returns. nodetext, options = self._execute_node(nodename, raw_string)