Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在Evennia的一个命令会得到多个结果?_Python_Mud - Fatal编程技术网

Python 为什么我在Evennia的一个命令会得到多个结果?

Python 为什么我在Evennia的一个命令会得到多个结果?,python,mud,Python,Mud,我正在制作一个文本游戏。我添加了一个名为Prop的新类型类。目前,它只有一个命令磨损。然后我创建了两个道具作为原型,并使用@spawn构建了它们。当我只拿着一个道具时,它的“穿戴”命令运行良好:穿戴手套返回您现在佩戴的是手套。但是,一旦我有了多个道具,我得到的就是.search消歧菜单,而我键入的任何东西似乎都不能真正消除歧义 我很确定这与cmdset合并有关,但我只能做到这一点。我做错了什么 mud/commands/prop_commands.py """ Prop commands "

我正在制作一个文本游戏。我添加了一个名为Prop的新类型类。目前,它只有一个命令磨损。然后我创建了两个道具作为原型,并使用@spawn构建了它们。当我只拿着一个道具时,它的“穿戴”命令运行良好:穿戴手套返回您现在佩戴的是手套。但是,一旦我有了多个道具,我得到的就是.search消歧菜单,而我键入的任何东西似乎都不能真正消除歧义

我很确定这与cmdset合并有关,但我只能做到这一点。我做错了什么

mud/commands/prop_commands.py

"""
Prop commands


"""


from evennia import CmdSet
from command import Command




class CmdWear(Command):
    """
    Wear or remove a prop


    Usage:
      wear <prop>
      don <prop>
      doff <prop>


    Causes you to wear or remove the prop. {wdon{n and {wdoff{n will only put the prop on or off; {wwear{n form will toggle between worn and unworn.
    """


    key = "wear"
    aliases = ["don", "doff"]
    locks = "cmd:holds()"
    help_category = "Objects"


    def parse(self):
        """Trivial parser"""
        self.target = self.args.strip()


    def func(self):
        caller = self.caller
        if not self.target:
            caller.msg("Wear what?")
            return


        target = caller.search(self.target)
        if not target:
            caller.msg("Couldn't find any %s." % self.target)
            return


        # assumes it's a Prop typeclass, so assumes it has this attribute
        if not target.db.wearable:
            caller.msg("That doesn't make any sense.")
            return


        if self.cmdstring in ("don", "doff"):
            should_wear = True if self.cmdstring == "don" else False
        else:
            should_wear = not target.db.worn


        if target.db.worn ^ should_wear:
            target.db.worn = should_wear
            caller.msg("You're %s wearing %s." % (
                "now" if target.db.worn else "no longer",
                target))
        else:
            caller.msg("You're %s wearing %s." % (
                "already" if target.db.worn else "not",
                target))




class PropCmdSet(CmdSet):


    def at_cmdset_creation(self):
        self.add(CmdWear())

事实证明,我没有得到一个。搜索消歧。相反,是命令本身被消除了歧义。解决方案是将CmdSet移动到对象以外的其他位置。然后,无论作用域中有多少对象,都只有一个命令

"""
Props are items that can be held, worn, etc.


"""


from evennia import DefaultObject
from commands import prop_commands




class Prop(DefaultObject):
    """
    Props are items that can be held, worn, stood on, and more.
    """
    def at_object_creation(self):
        self.cmdset.add(prop_commands.PropCmdSet, permanent=True)


        self.db.wearable = True
        self.db.worn = False