# Collision detection Ball

**URL:** <https://discourse.processing.org/t/collision-detection-ball/25210>\
**Category:** Coding Questions\
**Created:** [November 5, 2020, 5:05pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210 "2020-11-05T17:05:17Z")\
**Posts on this page:** 5\
**Page:** 3

<div class="post-metadata">

**Author:** ![MitchMitch2](https://avatars.discourse-cdn.com/v4/letter/m/f475e1/32.png) [@MitchMitch2](https://discourse.processing.org/u/MitchMitch2)\
**Post date:** [November 5, 2020, 8:40pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210/41 "2020-11-05T20:40:24Z")

</div>

But if I put the background (cols[index]); at the top, right under the draw. and the int index=int(random(10)); under the collision. It gives an error that the index cannot be resolved to a variable.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 5, 2020, 8:48pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210/42 "2020-11-05T20:48:52Z")

</div>

I saw this coming

this int index=int(random(10)); must be without the int : `index=int(random(10));`

before setup() say int index=int(random(10));

this makes index a global variable so it is known everywhere…

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 5, 2020, 8:56pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210/43 "2020-11-05T20:56:31Z")

</div>

MitchMitch3? Seriously?

---

<div class="post-metadata">

**Author:** ![MitchMitch3](https://avatars.discourse-cdn.com/v4/letter/m/91b2a8/32.png) [@MitchMitch3](https://discourse.processing.org/u/MitchMitch3)\
**Post date:** [November 15, 2020, 8:42pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210/44 "2020-11-15T20:42:59Z")

</div>

Now I put the int index=int(random(10)); all the way above the setup and under the collision it won’t but it starts with a random background color which is good enough for me, otherwise I bother you for even longer. Sorry for taking so long, thank you for all the support.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 15, 2020, 8:51pm UTC](https://discourse.processing.org/t/collision-detection-ball/25210/45 "2020-11-15T20:51:51Z")

</div>

BEFORE setup:

with int:

int index=int(random(10));

> [@MitchMitch3](#):
>
> under the collision

without the int : `index=int(random(10));`

[Previous page](https://discourse.processing.org/t/collision-detection-ball/25210.md?page=2)
