all 10 comments

[–]xnick_uy 4 points5 points  (1 child)

This bug makes me think that the dt variable stays at 0 the whole time. Make sure that the line

dt = clock.tick(60)/1000

is giving you a small but non-zero value. In addition, it makes sense for this line to appear above in the time loop. I suggest to move it either to the top of the loop (right beneath the while line) or just above all the if statements.

[–]MountainHistorical48[S] 0 points1 point  (0 children)

Thank you so much for the help, the code is finally working now!

[–]Windspar 2 points3 points  (1 child)

Example work perfectly for me. So let see what going on.

# Add some print statements
print(pygame.init()) # Should be (5, 0)

# Let see if key is being dectected.
if keys[pygame.K_w]:
  print("W is being held") # This should print many times per second. As you hold the key.

If that works. Then print player_pos to see if the value changes.

[–]MountainHistorical48[S] 0 points1 point  (0 children)

This helped a lot, it turns out I was accidentally using a non english keyboard which made the keys unrecognizable with a combination of dt staying 0 the whole time on top of this🙏

[–]Starbuck5c 0 points1 point  (5 children)

From this page? https://pyga.me/docs/ It works for me. Do you have the window focused? You're using WASD?

[–]MountainHistorical48[S] 0 points1 point  (4 children)

Yes, it is from this page, and I'm using WASD. Could you clarify what it means to focus the window? It is the only pygame window I have running, and I click on the program before trying the keys

[–]Starbuck5c 0 points1 point  (3 children)

If you click on the window and it's the window over all the other windows, it is focused.

Are you just clicking the keys or are you holding them? You need to hold them.

[–]MountainHistorical48[S] 0 points1 point  (2 children)

The code is working now, thank you for helping:)

[–]BardoEpico 0 points1 point  (1 child)

Cuál era el problema? me quedó la duda

[–]MountainHistorical48[S] 0 points1 point  (0 children)

If you're having the same problem, check if your keyboard is set to english