#๐Ÿ”’ neeed help

44 messages ยท Page 1 of 1 (latest)

jovial sluiceBOT
#

@brisk isle

Python help channel opened

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.

tight whale
#

Do you ever call main? What's the full code?

#

You also need to call pygame.init() as far as I know.

brisk isle
#

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)

jovial sluiceBOT
#

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.
brisk isle
tight whale
#

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.

brisk isle
#

im not good at python can u try explain what i can do to fix

tight whale
#

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.

brisk isle
#

there is a __ after main but for some reason it didnt paste

#

how can i fix the screen just closing tho

tight whale
#

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.

brisk isle
#

i just need help with the thing i asked please bro

#

not anything extras

tight whale
#

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.

brisk isle
#

how do i call main

tight whale
#

main()

#

Just as the last line of the file.

brisk isle
#

shud i remove the alr existing main()

tight whale
#

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.

brisk isle
#

it still says not responding

tight whale
#

Show the new code.

brisk isle
#

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()
tight whale
#

Like I said, you need to get rid of all the code at the end. You cannot use `input().

brisk isle
#

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

tight whale
#

main() needs to be un-indented. There should be no spaces before it.

#

You currently have main()inside of the main() function.

brisk isle
#

omg ur actually the best

#

where shud i put the other code tho

tight whale
#

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.

brisk isle
#

how to start a new thread

tight whale
#

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.

jovial sluiceBOT
#
Python help channel closed

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.