So I have this to get input from a user (just learned Python, using 2.7 because I was told to):
def get_move_order():
global move_order
move_order=[q for q in raw_input("Enter your move order: ")]
print "Checking the validity of your move..."
check_correct_moves_only()
And I have this to make sure that it only has the letters in the moves list:
def check_correct_moves_only():
moves = ['A','D','S','C','H']
if all(move_order) in moves:
return start()
else:
print "That's not a proper move!"
return get_move_order()
Problem is, that doesn't really work for some reason. I originally had it as something like this:
def check_correct_moves_only():
moves = ['A','D','S','C','H']
for q in move_order:
if q not in moves:
print "That's not a proper move!"
return get_move_order()
else:
return start()
But that will return input of something like AAAAAAR as correct six times (in this case, by printing "Player 1 ready!" six times and "That's not a proper move!" one time. I want it to check all seven (think turn based game, but seven orders given at once by each player) for this error before moving on to my other checks that are in start(), but I can't get the all function to work/maybe I'm using it wrong? I tried using any as well but that didn't work.
i would suggest the following to you:
You wrote
check_correct_moves_only
in a recursive way, which is not desirable for your problem. You should also useglobal
variables only when you really need them. Using parameters is more readable in most cases. If you need to use some information in different methods that are called separately, you could also write aclass
instead.