#π i have a problem where my games code crashes every time player tries to shoot a bullet at enemy
44 messages Β· Page 1 of 1 (latest)
@floral spear
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.
You have not defined BULLET_SIZE
Where's the code?
But ya, your code is attempting to use a variable that you haven't assigned.
ok, i chatted with ai and it said it was defined XD, i can send the code if you want
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
You do not define BULLET_SIZE anywhere in the code. What value are you expecting it to have?
im not 100% sure i started coding today XD so im new to all of this but bullet size needs to be 5 by 12 pixels, i cannot for the life of me figure out what to write or where to write it to make it work 
You should not be writing code like Pygame games if you just started today. Did you get this code from AI?
yes i have used a bit of ai to make the parts of code that i dont know, but the base game with the square, movements and enemies i made by looking at python codes on the internet, i have made ai add bullets damage and health
That's part of the problem. AI tends to produce broken slop. Even if you fix this one issue, there is a good chance there are other bugs in the code. You're unlikely to be able to debug code that you weren't able to write in the first place.
For this initial bug, though, you just need to assign a value to that name. You use = to assign names. Note the code you have at the top.
and next problem... what do i assign where 
If it's uppercase like BULLET_SIZE, that suggests the intent was for it to be a global constant, so it should be at the top with the other names that are uppercase.
Unless you're just doing this as a one off, I would highly encourage you to take a step back and actually learn Python. Clobbering code together from random sources will not teach you how to write code.
no iknow this is more of a one time fun thing XD, im currently watching tutoials on python
but is this where i assign it
That isn't assigning BULLET_TIME. Assignments have the syntax:
name_to_assign = the_value_to_give it
self.speed = BULLET_SPEED is assigning self.speed the value that BULLET_TIME holds.
ok so i need to change self speed to bullet size or time ?
ok imma try it gimme a sec
bullet speed says 8 but
self speed goes to bullet size
wait im a idiot XD
BULLET_SIZE
i just added it under the speed
now it works without any problems. thank you for the help i have been stuck here for an hour no joke 
That is part of why you should at least study the basics before attempting code like this. This is a extremely basic error (no offence). Knowing even a little of the basics would have made this easily solvable in seconds.
But, you're welcome. I'm glad it's fixed.
yeah i see now that i have to take some classes in python, i used c++ in highscool for automatoin class
The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.
so i can find most of what i need there for future faults ?
Those are learning resources. Debugging itself is a whole other set of skills, and I don't think resources in that list focus on debugging. Debugging is more something that you learn as you write code.
Everyone writes broken code initially, so writing code inevitably leads to you learning how to fix broken code.
yeah i figured XD i have some versions of the game
This help channel has been closed. 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.