Export to GitHub

evennia - issue #447

key_mergetypes problem on item cmdsets


Posted on Dec 19, 2013 by Massive Cat

I'm still having problems with the same sort of thing as Issue #391

Here's the steps to repeat it:

1) Put this in game/gamesrc/testcmdset.py

from ev import CmdSet

class TestCmdSet(CmdSet): key = "TestCmdSet" priority = 29 mergetype = "Replace" key_mergetypes = { 'Player' : 'Union', } no_exits = True no_objs = True no_channels = False

def at_cmdset_creation(self):
    """
    Populates the cmdset
    """

pass

2) Create TESTOBJ, set call:true, and put it next to your character 3) @py ev.search_object('#5654')[0].cmdset.add('game.gamesrc.testcmdset.TestCmdSet') 4) Now I can't use any commands, either from the Player cmdset or the Character cmdset. I expected Player commands to still be available.

5) Change the contents of game/gamesrc/testcmdset.py and @reload

from ev import CmdSet

class TestCmdSet(CmdSet): key = "TestCmdSet" priority = 29 mergetype = "Replace" key_mergetypes = { 'Character' : 'Union', } no_exits = True no_objs = True no_channels = False

def at_cmdset_creation(self):
    """
    Populates the cmdset
    """

pass

6) Now every command is back to being available. I can still use commands from my Character cmdset, and from my Player cmdset.

Comment #1

Posted on Jan 4, 2014 by Happy Bear

You are attempting an impossible combination by trying to merge a cmdset with a high priority onto a stack yet expecting it to behave differently with a cmdset further down in that stack.

Here is the merge order (ignoring channel/exit cmdsets): PlayerCmdSet (prio -5, Union) CharacterCmdSet (prio 0, Union) TestCmdSet (prio 29, Replace, Union for PlayerCmdSet)

What happens here is that these are merged in reversed priority order: CharacterCmdSet is merged onto the PlayerCmdSet to form a new, merged set named CharacterCmdSet. Onto this is then merged TestCmdSet, but since it is merging onto the merged set (named CharacterCmdSet) it will not trigger its special condition, which was set for PlayerCmdSet.

TestCmdSet and its key_mergetype exception will only work on the cmdset it is actually merging with, i.e. CharacterCmdSet. If you want it to operate on PlayerCmdSet further town in the stack), you need to insert it in the right place of the priority queue (give it say, priority=-4).

So what you want to do is not possible with this combination of permissions and stack. custom mergetypes were originally intended to be used mainly on simpler merges, on top of object-level cmdsets. I can see why it would be confusing, but I'm not sure how one would do the merging to have it work the way you want it to.

I'll try to expand the docs on just how mergetype comes into the merge order.

(The code also had a bug which made it impossible to insert custom cmdsets with priorities<0, this is fixed in latest push. This was due to the Empty sets having prio 0 and getting weeded out. Empty sets have prio -100 now instead)

Status: Reviewing

Labels:
Type-Defect Priority-Normal