Here is my code:
def moveEntity(entity):
print('forward=1')
print('backward=2')
print('left=3')
print('right=4')
direction = input('Where would you like to move?')
distance = input('How many units?')
if direction == 1:
entity.y = entity.y + distance
elif direction == 2:
entity.y = entity.y - distance
elif direction == 3:
entity.x = entity.x - distance
elif direction == 4:
entity.x == entity.x + distance
else:
print('invalid input')
When I run this function, and input any of the 4 options (1,2,3,4), the function always skips the 4 if/elif statements and executes the else statement. I can't figure out what is wrong with the code that I posted above. I have tried printing the values of the variables "direction" and "distance" after they have been inputted, and they both printed as the correct values. Directly after that, despite running through the if and elif statements, the else statements was still executed. Any help would be appreciated.
==
, not=
, so it will compare entity.x instead of assigning a new value to it. – user812786