#๐ neeed help
44 messages ยท Page 1 of 1 (latest)
@brisk isle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Do you ever call main? What's the full code?
You also need to call pygame.init() as far as I know.
import math
import random
import time
import pygame
from playsound import playsound
WIDTH = 1200
HEIGHT = 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Ruletka")
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
pygame.quit()
if __name__ == "__main__":
main()
MagSize = int(input("How Big Is The Mag?"))
PlayerLoaded = int(input("How Many Bullets Loaded"))
if PlayerLoaded > MagSize:
print("Invalid Amount")
PlayerLoaded = input("How Many Bullets Loaded?")
BulletN = random.randint(1,MagSize)
if PlayerLoaded <= BulletN:
print("You Died...")
elif PlayerLoaded > BulletN:
playsound("BlankFire.mp3")
print("You Survived...")
CPULoaded = random.randint(PlayerLoaded,MagSize)
Hey @brisk isle!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
thats the full code
You mean if __name__ == "__main__":. Also, you can't have all that code at the bottom. Pygame "owns" the thread. You can't run blocking code like input.
im not good at python can u try explain what i can do to fix
I did.
Get rid of all the code at the bottom under the if __name__ == '__main__': main(), and fix your if __name__ == '__main__'. You appear to be missing __ after __main.
If you're new to Python, you shouldn't really be jumping right into Pygame.
there is a __ after main but for some reason it didnt paste
how can i fix the screen just closing tho
Get rid of that if altogether. Those are only needed in a small number of circumstances.
Just have main() as the last line in your program.
That is the fix. The freezing was caused by the code you had at the bottom, and the windows closing is likely due to the if being wrong and main not being called.
how do i call main
shud i remove the alr existing main()
Well, you can just remove the if line, then dedent the existing main(). It doesn't matter. You just need main().
You just need one main() at the end.
it still says not responding
Show the new code.
import math
import random
import time
import pygame
from playsound import playsound
WIDTH = 1200
HEIGHT = 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Ruletka")
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
pygame.quit()
MagSize = int(input("How Big Is The Mag?"))
PlayerLoaded = int(input("How Many Bullets Loaded"))
if PlayerLoaded > MagSize:
print("Invalid Amount")
PlayerLoaded = input("How Many Bullets Loaded?")
BulletN = random.randint(1,MagSize)
if PlayerLoaded <= BulletN:
print("You Died...")
elif PlayerLoaded > BulletN:
playsound("BlankFire.mp3")
print("You Survived...")
CPULoaded = random.randint(PlayerLoaded,MagSize)
main()
Like I said, you need to get rid of all the code at the end. You cannot use `input().
import math
import random
import time
import pygame
from playsound import playsound
WIDTH = 1200
HEIGHT = 800
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Ruletka")
def main():
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
pygame.quit()
main()
it just flashes the window
then disappears
main() needs to be un-indented. There should be no spaces before it.
You currently have main()inside of the main() function.
You can't use it without a lot of complication. You should use Pygame to take input.
To use that code, you'd need to start a new thread, and that adds a lot of complications.
how to start a new thread
I do not think your want to get into multithreading.
At the least, that's probably too large of a topic to properly teach in a Discord discussion.
I would look into established tutorials for that on a reputable site like Real Python
But in reality, I would just drop either Pygame or the need for input. There's little point in using a library line Pygame if you're also going to use input.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.