What is out there? Hard and soft codebases of choice.


  • Coder

    @Griatch said in What is out there? Hard and soft codebases of choice.:

    Edit: But if with "passive condition" you mean something like "at the moment of entering bob, if this condition is True then get back this version of the command, otherwise this other version", then you need to do a little more work:

    You could solve this by adding all your conditional commands to the cmdset and tell them not to merge but to remain separate (but same-named) in the set. You then plug in your own MULTIMATCH_ERROR handler. When you use "bob" you will then get multiple possible command-matches. The normal result on a multimatch is to give you a list of commands and let you pick the one you want to use (it may matter if you are using the "push" command on the red or blue button after all). But your multimatch handler could instead check the condition and run only the command the condition dictates.

    A bit of a necro of this thread, but it struck me that that the dynamic changing of commands based on a condition is a lot easier in Evennia than I suggested above. The question was essentially "at the moment of entering bob, if this condition is True, get back this version of the bob command, otherwise get the other condition". The way to go is to use locks. Here we decide which bob command to use depending on if the caller has the Attribute "foo" or not:

    from evennia import Command, CmdSet
    
    class CmdBob1(Command):
        key = "bob"
        locks = "cmd: not attr(foo)"
        def func(self):
            # stuff this first bob command does
    
    class CmdBob2(Command):
        key = "bob"
        locks = "cmd: attr(foo)"
        def func(self):
            # stuff this second bob command does
    

    Explanation: Above we create two Evennia Commands, both keyed as "bob" but doing (supposedly) different things. Each also has a lock string. Locks is a mini-language in Evennia, where you call small python functions that always return True/False and combine their returns into the result of the lock. In this case the lock string is cmd:attr(foo) and cmd:not attr(foo) respectively. The cmd bit is the lock type. For a Command, if the cmd type lock is not passed, the entire Command is unavailable to the player at this time. The lock is using the attr(name) lock function. This is a predefined lock function that checks if the caller has an Attribute with the given name ("foo") at all. So in this case, if the "foo" Attribute is set, CmdBob1 will fail the lock and CmdBob2 will pass it and vice versa. You could of course define your own custom lock funcs like is_it_full_moon etc. It's a normal Python function you just tell Evennia to treat as a lock function.

    ... We now just need to add these two commands into their own cmdsets and add them both to whatever object should be able to use or supply the "bob" command(s). When you then enter "bob" on the input line you will get the result of either CmdBob1 or CmdBob2 depending on if you have the "foo" attribute set on yourself or not.

    I added it as a Q&A hint to the Evennia tips and tricks section.


Log in to reply
 

Looks like your connection to MU Soapbox was lost, please wait while we try to reconnect.