I am very new to codding and am trying to make a game I can call my own. I don't undertand what the error means but here is my code:
import pgzrun
import math
import random
WIDTH = 800 #5
HEIGHT = 600
CENTER_X = WIDTH/2
CENTER_Y = HEIGHT/2
CENTER = (CENTER_X, CENTER_Y)
FONT_COLOR = (221, 160, 221) #10
ozol = 0
game_over = False
ozolith = Actor("ozolith") #15
def draw():
screen.clear()
ozolith.draw()
draw_counters(ozol) #20
def place_ozolith():
ozolith.x = CENTER_X
ozolith.y = CENTER_Y
#25
def draw_counters(ozol):
screen.draw.text(str(ozol), fontsize=40, center=CENTER, color=FONT_COLOR)
def on_mouse_down(pos):
if ozolith.collidepoint(pos): #30
ozol += 1
place_ozolith
else:
quit()
#35
place_ozolith
pgzrun.go()
Here is the error message
Traceback (most recent call last):
File "C:\Program Files\Python38\python-games\GameCraft\GameCraft.py", line 38, in <module>
pgzrun.go()
File "C:\Program Files\Python38\lib\site-packages\pgzrun.py", line 31, in go
run_mod(mod)
File "C:\Program Files\Python38\lib\site-packages\pgzero\runner.py", line 113, in run_mod
PGZeroGame(mod).run()
File "C:\Program Files\Python38\lib\site-packages\pgzero\game.py", line 217, in run
self.mainloop()
File "C:\Program Files\Python38\lib\site-packages\pgzero\game.py", line 247, in mainloop
self.dispatch_event(event)
File "C:\Program Files\Python38\lib\site-packages\pgzero\game.py", line 172, in dispatch_event
handler(event)
File "C:\Program Files\Python38\lib\site-packages\pgzero\game.py", line 164, in new_handler
return handler(**prepped)
File "C:\Program Files\Python38\python-games\GameCraft\GameCraft.py", line 31, in on_mouse_down
ozol += 1
UnboundLocalError: local variable 'ozol' referenced before assignment
It happens once I click on the image which is stuck on the top left corner.