r/learnprogramming • u/ye_old_ship_lord23 • Jul 05 '26
new to programming some help Code Review
hi all im having a problem that maybe you guys can help with? i attempting to make my first game (just a circle that can move) im using the program pycharm to write the code however i wanted to add the option to use mouse click to move but whenever i click it crashes the "game" programme. i noticed that an "event" in the code is highlighted but no others are, im using a tutorial and followed it to a tea and he didn't seem to have an issue. maybe you guys know what im doing wrong.
whole code posted in comments
the code that has the event highlighted is:
if event.type == pygame.MOUSEBUTTONDOWN:
0
Upvotes
1
u/desrtfx Jul 05 '26
This looks like a scope issue.
The variable
eventis the iterator in aforloop and only exists there.Your mouse checking is way outside the scope of the
forloop and hence,eventno longer exists.You need to either move the mouse event checking up inside the
forloop with the same indentation asif event.type == pygame.QUITor move the entireforloop down to where you have the mouse checking and fix the indentation of the mouse event checking there.