#πŸ”’ 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
#

is there someone that can look at my code to se if there is something i have missed or simply forgotten to do.

trail shuttleBOT
#

@floral spear

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.

tired stump
#

You have not defined BULLET_SIZE

lapis whale
floral spear
#

ok, i chatted with ai and it said it was defined XD, i can send the code if you want

lapis whale
#

!paste

trail shuttleBOT
#
Pasting large amounts of code

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.

floral spear
#

there the complete code is

lapis whale
floral spear
#

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 kek

lapis whale
#

You should not be writing code like Pygame games if you just started today. Did you get this code from AI?

floral spear
#

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

lapis whale
#

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.

floral spear
#

and next problem... what do i assign where kek

lapis whale
#

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.

floral spear
#

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

lapis whale
#

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.

floral spear
#

ok so i need to change self speed to bullet size or time ?

lapis whale
#

Wait, the error is BULLET_SIZE

#

It's BULLET_SIZE that you need to assign a value to.

floral spear
#

ok imma try it gimme a sec

#

bullet speed says 8 but

#

self speed goes to bullet size

#

wait im a idiot XD

lapis whale
#

BULLET_SIZE

floral spear
#

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 kekwlaugh

lapis whale
#

But, you're welcome. I'm glad it's fixed.

floral spear
#

yeah i see now that i have to take some classes in python, i used c++ in highscool for automatoin class

lapis whale
#

I'd give this list a look-over:

#

!resources

trail shuttleBOT
#
Resources

The Resources page on our website contains a list of hand-selected learning resources that we regularly recommend to both beginners and experts.

floral spear
#

so i can find most of what i need there for future faults ?

lapis whale
#

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.

floral spear
#

yeah i figured XD i have some versions of the game

trail shuttleBOT
#
Python help channel closed for inactivity

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.