# 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?

**URL:** <https://discourse.processing.org/t/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-doesnt-say-the-specific-problem-can-you-help/36438>\
**Category:** Processing.py\
**Created:** [April 19, 2022, 9:58am UTC](https://discourse.processing.org/t/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-doesnt-say-the-specific-problem-can-you-help/36438 "2022-04-19T09:58:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 19, 2022, 9:58am UTC](https://discourse.processing.org/t/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-doesnt-say-the-specific-problem-can-you-help/36438/1 "2022-04-19T09:58:56Z")

</div>

“”"  
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!")
```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 19, 2022, 10:21am UTC](https://discourse.processing.org/t/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-doesnt-say-the-specific-problem-can-you-help/36438/2 "2022-04-19T10:21:30Z")

</div>

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 –

```python
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.

---

<div class="post-metadata">

**Author:** ![montoyamoraga](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/montoyamoraga/32/16457_2.png) [@montoyamoraga](https://discourse.processing.org/u/montoyamoraga)\
**Post date:** [April 20, 2022, 10:59pm UTC](https://discourse.processing.org/t/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-doesnt-say-the-specific-problem-can-you-help/36438/3 "2022-04-20T22:59:50Z")

</div>


