# Help: Keeping Score: Ball \> Hoop

**URL:** https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785
**Category:** Uncategorized
**Created:** [September 21, 2002, 10:15pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785 "2002-09-21T22:15:28Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Dryst](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@Dryst](https://forum.kirupa.com/u/Dryst)
#### Post date: [September 21, 2002, 10:15pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/1 "2002-09-21T22:15:28Z")

</div>

Ok first off, HI!!! My name is Jeff Snow. You all can call me Dryst or jeff, whatever.

Ive been browsing these tutorials and message boards for a few weeks, so here I am :).

* * *

## Ok heres the problem

I made this Ball+Gravity thing, and now I want to add a Hoop and have it keep score. I know about the \_root.total = \_root.total + 1; part of the code, but how would I go about making it only work if the ball goes through the net from the top.  
And what extra code would I have to add to make the net play a little movie clip animation when the ball passes through?.

This is what I have so far [http://members.cox.net/dryst17/Gravity.html](http://members.cox.net/dryst17/Gravity.html)

Thanks alot everyone, cya

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 21, 2002, 11:24pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/2 "2002-09-21T23:24:50Z")

</div>

Well if you had an mc called hop (just the top rim), you could use:

if (\_root.ball.hitTest(\_x, \_y, true)) {  
\_root.score++  
}

So when the ball goes through the center of the hoop (providing that’s where the registration point is) the score will increase. But you need to set it so that the score only increases upon the first contact, and not repeated contacts (otherwise the score will continue increasing as it’s going “through” the hoop) - which isn’t too difficult to do, but also have it so that the score dosn’t increase when the hit test is true if the ball bounces back up.

You can also use a hit test to make sure that the ball only register a score when it drops from the top and not just hitting the hoop sideways.

Also use !drag - drag = false - (if you use drag as a variable to set whether the balls is being dragged or not) so that you can’t cheat and just drag the ball through.

It sounds like an interesting idea and if I get a mo, I’ll try and do a fla. unless someone already has, or has better ideas.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 21, 2002, 11:37pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/3 "2002-09-21T23:37:35Z")

</div>

I’ll get right on that! thanks! =)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 21, 2002, 11:52pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/4 "2002-09-21T23:52:41Z")

</div>

I think the ball needs to be tagged ‘ball’ or something, I think the rest of the code is fine, its just not understanding what the ball part is in (\_root.ball.hitTest ect…)

The ball is a movie clip, the movie clip is named ball. the balls code is this

onClipEvent (load) {  
gravity = 2;  
floor = 383;  
floorx1 = 17;  
floorx2 = 533;  
bounce = 0.80;  
speedx = 0;  
speedy = 0;  
}  
onClipEvent (enterFrame) {  
if (pressing) {  
// if we are pressing  
// drag the object  
startDrag (this, true);  
// calculate the speed  
speedx = this.\_x-x0;  
speedy = this.\_y-y0;  
// set a new reference point  
x0 = this.\_x;  
y0 = this.\_y;  
} else {  
stopDrag ();  
speedy = speedy+gravity;  
this.\_x += speedx/7;  
this.\_y += speedy/7;  
if (this.\_y\>floor) {  
this.\_y = floor;  
speedy \*= -bounce;  
}  
if (this.\_x\<floorx1) {  
this.\_x = floorx1;  
speedx \*= -bounce;  
}  
if (this.\_x\>floorx2) {  
this.\_x = floorx2;  
speedx \*= -bounce;  
}  
}  
}

And the hoop looks like this so far

onClipEvent (load) {  
if (\_root.ball.hitTest(\_x, \_y, true)) {  
\_root.total = \_root.total + 1;}  
}

but its not registering to the dynamic text with the var: total to raise +1 … hmm whats wrong

-Dryst

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 21, 2002, 11:59pm UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/5 "2002-09-21T23:59:05Z")

</div>

It’s easier if your post you fla, than typing out all the code! Post it if you can, if not, I’m looking at your code now, anyway. ![](http://flex.funkyolive.com/im/crash.gif)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:00am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/6 "2002-09-22T00:00:24Z")

</div>

Well first of all

onClipEvent (load) {  
if (\_root.ball.hitTest(\_x, \_y, true)) {  
\_root.total = \_root.total + 1;}  
}

should be

onClipEvent (enterFrame) {  
if (\_root.ball.hitTest(\_x, \_y, true)) {  
\_root.total++; // same as doing \_root.total = \_root.total + 1  
}

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:05am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/7 "2002-09-22T00:05:12Z")

</div>

You rock! that got it working, but as you predicted, the score goes up fast, as the ball is inside the hoop object.

here is the .fla

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:13am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/8 "2002-09-22T00:13:29Z")

</div>

Well that’s the score problem sorted, now for the others…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:16am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/9 "2002-09-22T00:16:27Z")

</div>

I dont have MX yet bro…  
cant open your file

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:17am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/10 "2002-09-22T00:17:42Z")

</div>

Flash 5 format

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:35am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/11 "2002-09-22T00:35:32Z")

</div>

Thank you so much!

Ok on the checklist there is:

1. no drag cheating, this one should be easy, i wish i knew the code though lol

2. make it so it cant score from the side (is there any way to make it bounce off the side of the rim?

3. Im going to make a net with a movieclip animation, is there a way to trigger the nets animation when there is a score?

hmm

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:41am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/12 "2002-09-22T00:41:04Z")

</div>

Possibly add a small invisible box on the outer sides of the hoop and code it to react with the ball using something similar to the bounce code on the ball?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 12:43am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/13 "2002-09-22T00:43:01Z")

</div>

I thought off the net alread! I’m trying little bits here and there while I drink my pepsi and munch chocolate. That part is easy.

The rim - just put a movie clip there and have it so that if the ball hits, the \_x and \_y are reversed so it bounces off.

The drag one needs a variable.

But you also need to either increase the size of the ball, decrease the size of the hoop, or increase the hit area, because \_x, \_y in the hit test works if the ball goes the centre of the hoop, but the ball is small so it still goes through - even though it’s not in the centre, and no score is registered.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 1:06am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/14 "2002-09-22T01:06:37Z")

</div>

Here the fla with the rim done - works ok. The zip has MX and Flash 5

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 1:14am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/15 "2002-09-22T01:14:10Z")

</div>

And here’s the dragging prevention done. I know I should have just edited the other post, but it’s 2:10 am here - and I haven’t the energy…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 1:16am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/16 "2002-09-22T01:16:46Z")

</div>

Your help is Greatly appreciated. I am so thankful for everything!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 1:23am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/17 "2002-09-22T01:23:15Z")

</div>

No probs. As I far as I can remember, the only thing needed now is to prevent the ball from scoring if it bounces up.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 1:43am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/18 "2002-09-22T01:43:23Z")

</div>

I am trying to add another rim on top of the first ‘rim’ that will make it bounce up, Im trying to code it on the \_y axis,

here take a look

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 2:46am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/19 "2002-09-22T02:46:15Z")

</div>

you have helped more than enough, I have nothing but respect for you and your kindess. thanks for everthing and go to bed!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 22, 2002, 2:47am UTC](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785/20 "2002-09-22T02:47:18Z")

</div>

Reposted it - the other one was dodgy!

Try this one

[Next page](https://forum.kirupa.com/t/help-keeping-score-ball-hoop/5785.md?page=2)
