From 7f63393cb7b6d21136010133138ce67d4a8fceea Mon Sep 17 00:00:00 2001 From: Dan Feeney Date: Wed, 28 Sep 2016 01:17:48 -0500 Subject: [PATCH] modified msg_contents to allow objects without get_display_name to be included in mapping --- evennia/objects/objects.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 8d55abe1e1..c85ed84154 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -559,14 +559,16 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): {}-style format syntax. The keys of `mapping` should match named format tokens, and its values will have their `get_display_name()` function called for each object in - the room before substitution. + the room before substitution. If an item in the mapping does + not have `get_display_name()`, its string value will be used. Example: Say char is a Character object and npc is an NPC object: + action = 'kicks' char.location.msg_contents( - "{attacker} attacks {defender}", - mapping=dict(attacker=char, defender=npc), + "{attacker} {action} {defender}", + mapping=dict(attacker=char, defender=npc, action=action), exclude=(char, npc)) """ contents = self.contents @@ -575,7 +577,10 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)): contents = [obj for obj in contents if obj not in exclude] for obj in contents: if mapping: - substitutions = {t: sub.get_display_name(obj) for t, sub in mapping.items()} + substitutions = {t: sub.get_display_name(obj) + if hasattr(sub, 'get_display_name') + else str(sub) + for t, sub in mapping.items()} obj.msg(message.format(**substitutions), from_obj=from_obj, **kwargs) else: obj.msg(message, from_obj=from_obj, **kwargs)