vendredi 31 mars 2017

python executing both if and else statement together

I am not sure why, but python is executing the if statement then the else statement in the same iteration

i'm cutting out unimportant code:

from livewires import games
...
...
def update(self):
  if games.keyboard.is_pressed(games.K_s):
    if self.y == games.screen.height/3:
      self.y = games.screen.height/2
    else:
      self.y = games.screen.height

In my mind it should go: if 's' is pressed: then, if the height is equal to whatever do whatever otherwise, do whatever2

But the computer is going: if 's' is pressed then, make the height equal to whatever and since the height is no longer equal to whatever, make it equal to whatever2

I have tried this by using single if statements with 'and' operators and all kinds of funky ways of doing it, but everything I do, the code just seems to move to the next line regardless of if/elif/else

I even tried implementing a sort of timer that kind of works, but is unreliable.

Aucun commentaire:

Enregistrer un commentaire