Pygame display.set_mode doesn't work in replit?

Question:
How come display.set_mode doesn’t work in replit?
Repl link:

https://replit.com/@NeonG4/Pyhton#main.py

window = pygame.display.set_mode((window_width, window_height)) #Broken, doesn't work in replit? 

Could it just be my code?

Pyhton - Python Repl - Replit link for the repl

Hi @NeonG4 thanks for your question. I forked your Repl but it appears you have already tried to change the code. I don’t see any reference to pygame.display.set_mode.

I’ve seen quite a lot of pygame examples recently which seemed to work fine. I’ll be back in a few minutes with an example which hopefully you can fork and edit.

Hi again @NeonG4 please take a look at the following Repl

https://replit.com/@IanAtReplit/Flappy-Bird#main.py

Line 62 references the same code you were having issues with:

SCREEN = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT))

Hopefully you can use this to make your code work.

So, instead of using pygame I switched to pynput - keyboard. I went to stack overflow, click - Python, check if arrow key pressed - Stack Overflow and I ran the answer by user19616370, but it didn’t fix it. Is there a better way to do it that you can explain? Thanks!

Hi @NeonG4 I think you need to provide more information. I don’t yet know what it is that you want your code to do.

Go into as much information as you can and the community will try to help you solve your issue.

1 Like

Sorry.
Me and my friend are trying to code a platformer, and we want to make it controlled by arrow keys. We have started it, and I wanted to add left-right physics. I need to change the x_vel variable (standing for x velocity) change by 1 once the right arrow key is pressed, and -1 when the left. I don’t know how to detect that press, so I came to replit ask.

I hope that this is helpful?

Thanks. That’s really helpful!

Have you looked at Kaboom.js? This is an excellent tutorial for creating a platform game Learn How to Make a Platform Game with Kaboom.js | Kaboom.js Fundamental Full Course in 1.5 Hours - YouTube

1 Like

By the looks of that, is that in javascript? I sort of want it in python, but if that’s not possible, I can do it in javascript.

1 Like

Of course! I’d really recommend Pygame if you are going to create a platformer.

https://coderslegacy.com/python/pygame-platformer-game-development/

1 Like

And for some reason, line 15 doesn’t work!

displaysurface = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.error: No available video device

I made a new project using the Pygame template (rather than the python template) and copied in your code:

https://replit.com/@IanAtReplit/PyGameTest#main.py

Please fork this. It will help you get started.

2 Likes

Alright! Thank you so much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.