#๐Ÿ”’ This damn code won't work

27 messages ยท Page 1 of 1 (latest)

carmine hornet
foggy bisonBOT
foggy bisonBOT
#

@carmine hornet

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.

cold glade
carmine hornet
#

It's a bossfight game, and when I press start in the menu it instantly crashes, I can't even ctrl+c the error

cold glade
#

Are you running it by double clicking the script icon?

carmine hornet
#

I double click the .py file, the window pops up, and then when I press start it crashes, so ye

cold glade
#

Ya, don't run scripts that way during development. It prevents you from seeing errors. Run the code via the terminal instead.

carmine hornet
#

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

cold glade
carmine hornet
#

Oh that is why crashes, but what about the game loop

cold glade
carmine hornet
#

how to fix the game loop thing?

cold glade
#

What about the game loop?

carmine hornet
#

File "C:\Users\myname\Desktop\Szafki\Szafka 2\Python\Pythoni-GiBoss-God.py", line 157, in <module>
game_loop()

cold glade
#

That's the same error. That's a stack trace showing you where the error is.

carmine hornet
#

Do I need to add it to <module> for it to work properly?

cold glade
carmine hornet
#

To global, amirite

cold glade
#

Yes, you need to add the name to the global statement with the other names.

carmine hornet
#

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

foggy bisonBOT
#
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.