code order changes the result..

someone knows if order of a code inside one method have different results… here is my case:

If i change the order between them, let say, the codeblock for self.keyMap[“down”] placing bottom of codeblock self.keyMap[“up”], the “up” controls does not respond, just moves but not animate and do not make sound too, but “down” controls works perfectly.

If inverting order, codeblock for self.keyMap[“up”] put botton of self.keyMap[“down”], then “down” is not working, and “up” yes.

Resuming, the problem is codeblock located above, i´m not professional in python, but i have intended that no matter the condition orders in the same method, or maybe i´m wrong…

If i replace if by elif, the result is other but not working too…
what could be… thanks.

I think that you’ll find that the problem is the else after the troublesome pair.

As you currently have it, I believe that it is related to the latter of the two (whichever that is at the time). Thus, we could see the following situations (taking the order given in the picture), I believe, with the following results, I think:

  1. “Down” is pressed, “up” is pressed:
    Two opposing movements are made. Since “down”'s code gets executed first, and sets the flag that prevents it for “up”, only “down”'s animation plays.

  2. “Down” is not pressed, “up” is pressed:
    The first if-statement is skipped (since “down” is not pressed), the player moves in response to the “up” press, and “up”'s animation plays.

  3. “Down” is not pressed, “up” is pressed:
    Both if-statements are skipped (since neither key is down), and the else is run.

  4. “Down” is pressed, “up” is not:
    The first if-statement runs, moving the character and starting the animation. Then, because the second if-statement fails (since “up” is not pressed), the else runs, including the pose.

I think, at least, that that is your problem.

If so, then you might solve it, I think, by either setting a boolean in each if-statement, before their inner if-statements, and test that instead of using the final else statement, something like this:

hasMoved = False

if self.keyMap["down"] == 1:
#Note that the brackets aren't, I don't think, called for above ;)
    hasMoved = True
    self.gabriel.setY(self.gabriel, timing*4)
    # ... etc.

if self.keyMap["up"] == 1:
    hasMoved = True
    self.gabriel.setY(self.gabriel, -timing*4)
    # ... etc.

if not hasMoved:
    self.gabriel.stop()
    # ... etc.

Otherwise, you might test both “up” and “down” in an over-arching if-statement, and then have your else relate to that, along these lines:

if self.keyMap["up"] == 1 or self.keyMap["down"] == 1:
    if self.keyMap["down"] == 1:
        # ... etc.

    if self.keyMap["up"] == 1:
        # ... etc.

else:
    self.gabriel.stop()
    # ... etc.

There may well be other solutions, and I may well be wrong about the problem, but that is what comes to mind to me. :slight_smile:

Thank you for your explaining, going to test now ! :stuck_out_tongue:

The first one works perfectly !,

is running and walking very good, backward walk and forward runs…

just a warning in the console :

audio(error): _channel->stop(): The specified channel has been reused to play another sound. 
:audio(error): _channel->stop(): An invalid object handle was used.

repeated multiples times…

anyway game runs … thank you mister… !

Just a heads up - you can re-write the following line:

if(self.turnoGabriel == True)and(self.turnnoAlfredo == False):

into:

if self.turnoGabriel and not self.turnnoAlfredo:

ahh, you´re right, is that i´m learning python with panda together… thank for the tip…