lundi 14 août 2017

Any suggestions on how to improve my input commands

I am looking for any suggestions that will improve, simplify or even tidy up my input commands. I have seen that repetition is not a good habit.

while(char.health > 0):
    print("_____________________________________")
    line = input("\n>").lower().split()
    if len(line) < 1:
        print ("{} doesn't understand the command?".format(char.name))
    elif line[0] == "go":
        commands.movement()
    elif line[0] == "quit":
        commands.quit()
    elif line[0] == "rest":
        commands.rest()
    else:
        print ("{} doesn't understand the command?".format(char.name))

I have seen some people use a dict like this:

    cmd = {'go' : commands.movement()} 

When i do this it seems to run the def without them being called! All help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire