Hi i am new here. Everytime I run my code, it plays for a second, then stops playing and red text comes up, but it doesn't say the specific problem. Can you help?

“”"
This is my program Hit.it. The player is the ball and the aim of the game is to hit the dogs coming from the sky. If the player hits more than 10 dogs, they win. If not, they lose.
“”"
add_library(“sound”)

ellX = 350 #initial dog position
ellY = 0
count = 0 #count score
ball = 0
countdown = 5 #beginning countdown
moveDown = True #dog starts moving down

def setup():
global sf, x, bgImage, y, speed, acceleration, countdown
countdown = 5
x, y = -50, -50
speed = 2
acceleration = 0.4
size(800, 600)
frameRate(1)
sf = SoundFile(this,“backgroundmusic.mp3”)
sf.play()
bgImage = loadImage(“backgroundimage.jpeg”)
dog = loadImage(“dog.png”)

def mouseReleased():
global x, y, speed
x = mouseX
y = mouseY
speed = 1

def draw():
global bgImage, x, y, speed, dog, count, moveDown, ellX, ellY, ball, countdown
image(bgImage, 0, 0, width, height)
stroke(0, 255, 0)

image(dog, ellX, ellY, 130, 50) #initial position of dog 
text("Score:", count, 450, 50)

textSize(18)
text("Welcome to Hit.it! Hit 15 or more dogs and you will win!", width/8, height/8)
text("Get ready to play once the timer runs out!", width/6, height/6)
textSize(50)
text(countdown, height/2, width/2)

if countdown > 0:
    countdown = countdown - 1
else:
    noLoop()
  
y = y + speed
speed = speed + acceleration
if y > height:
    speed = speed * -1
    y = height

if moveDown == True:
    ellY = ellY + 4 #dogs always moves down at speed of 4
if ellY <= 650:
    moveDown = True #how far down it moved 
if ellY> 650:
    ellY = 0
    ellX = random (30, 570) #random placement 
    moveDown = True
    count = count + 1
    
if ball < y + 50 and y > ellY - 50 and ball < x + 50 and ball > x - 50: #what happens when the ball hits the dog 
    ellY = 0
    ellX = random(30, 570)
    moveDown = True
    count= count + 1
    
if count < 10:
    text("You lost!")
else:
    text("Congratulations, you won!")

Welcome @maya

It would help if you could tell us what the error message (red text) says. I’m guessing you’re missing dog in the global line of your setup() block –

def setup():
    global sf, x, bgImage, y, speed, acceleration, countdown, dog

* BTW: insert all of your code between triple-backticks (``` and ```) so it looks properly formatted here.

3 Likes