#๐ This damn code won't work
27 messages ยท Page 1 of 1 (latest)
Click here to see this code in our pastebin.
@carmine hornet
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 haven't said what it's supposed to do or what the problem is.
It's a bossfight game, and when I press start in the menu it instantly crashes, I can't even ctrl+c the error
Are you running it by double clicking the script icon?
I double click the .py file, the window pops up, and then when I press start it crashes, so ye
Ya, don't run scripts that way during development. It prevents you from seeing errors. Run the code via the terminal instead.
ok
File "C:\Users\myname\Desktop\Szafki\Szafka 2\Python\Pythoni-GiBoss-God.py", line 157, in <module>
game_loop()
~~~~~~~~~^^
File "C:\Users\myname\Desktop\Szafki\Szafka 2\Python\Pythoni-GiBoss-God.py", line 133, in game_loop
player_pos += vel
^^^^^^^^^^
UnboundLocalError: cannot access local variable 'player_pos' where it is not associated with a value
Yeah I got the code from chatgpt because I don't know how to code
You're attempting to reassign the global player_pos without declaring it to be a global. You need to add that name to the existing global statement at the top of the function.
Oh that is why crashes, but what about the game loop
AI-generated code is buggy and broken. You will be running into petty issues like this constantly if you're having it generate code without understanding what it's generating.
how to fix the game loop thing?
What about the game loop?
File "C:\Users\myname\Desktop\Szafki\Szafka 2\Python\Pythoni-GiBoss-God.py", line 157, in <module>
game_loop()
That's the same error. That's a stack trace showing you where the error is.
Do I need to add it to <module> for it to work properly?
I said what you need to fix here: #1429469180964376787 message
To global, amirite
Yes, you need to add the name to the global statement with the other names.
Okay so the answer was right in front of my nose
Thank for helping
Will post it on my itch io page (it's a second gen game because it's in fullscreen, first gen ones were in a window) after I fix it
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.