# Changing Boolean to Int in a custom function

**URL:** <https://discourse.processing.org/t/changing-boolean-to-int-in-a-custom-function/15140>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 2, 2019, 6:20am UTC](https://discourse.processing.org/t/changing-boolean-to-int-in-a-custom-function/15140 "2019-11-02T06:20:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanchun](https://avatars.discourse-cdn.com/v4/letter/n/94ad74/32.png) [@nathanchun](https://discourse.processing.org/u/nathanchun)\
**Post date:** [November 2, 2019, 6:20am UTC](https://discourse.processing.org/t/changing-boolean-to-int-in-a-custom-function/15140/1 "2019-11-02T06:20:41Z")

</div>

Hi! I am trying to create a bunch of random circles to appear and then bounce around the edges of the screen. I got everything I wanted so far except the “checkEdge” function. I keep getting the error that says “The operator \< is undefined for the argument type(s) int[], int[]”. I was reading online that you can change a boolean result to its corresponding int value but I was unsure of how to do that. I included the full code incase you needed to see it but the part I need help on is the very last function “void checkEdge”. Any help would be greatly appreciated!

```auto
int numParticle = 25;
int[] posX = new int[numParticle];
int[] posY = new int[numParticle];
int[] radius = new int[numParticle];
int[] dirX = new int[numParticle];
int[] dirY = new int[numParticle];
color[] randomColor = new color[numParticle];

void setup() {
  size(500,500);
  colorMode(HSB);
  for (int i = 0; i < numParticle; i++) {
    posX[i] = int(random(500));
    posY[i] = int(random(500));
    radius[i] = int(random(100));
    dirX[i] = int(random(1,5));
    dirY[i] = int(random(1,5));
    randomColor[i] = color(random(255), random(255), random(255));
  }
}

void draw() {
  background(255);
  drawParticles();
  update();
  checkEdge();
}

void drawParticles() {
   noStroke();
   for(int i =0; i < numParticle; i++) {
     fill(randomColor[i]);
     ellipse(posX[i], posY[i], radius[i], radius[i]);
   }
}
void update() {
  for(int i=0; i < numParticle; i++) {
    posX[i] += dirX[i];
    posY[i] += dirY[i];
  }
}
void checkEdge() {
  if(posX > width-radius || posX < radius) dirX = -dirX;
  if(posY < radius || posY > height - radius) dirY = -dirY;
}

```

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 2, 2019, 7:53am UTC](https://discourse.processing.org/t/changing-boolean-to-int-in-a-custom-function/15140/2 "2019-11-02T07:53:20Z")

</div>

There is a difference between Int and Int[].

Int \> Int is how it‘s supposed to be, but what you did is Int[] \> Int[], which can‘t give you a result.

You just need to look at the function above that one to see the difference in how you are refering to posX.

posX is an Int[], while posX[0] is an Int in your Code.

In that function you suddenly went from your variables being Int Arrays to refering to them as single Ints.

The Error messages tell you what you did wrong, not how it should be, since there can be different approaches that are right in some cases.

Also, i don‘t really know what you mean with that change Bool to Int… You should be able to just use a bool as Int, since they are just that… either 0, or 1.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [November 2, 2019, 9:53am UTC](https://discourse.processing.org/t/changing-boolean-to-int-in-a-custom-function/15140/3 "2019-11-02T09:53:46Z")

</div>

as @Lexyth (nice to see you here) told you, need to check the whole array

```auto
void checkEdge() {
  for (int i=0; i < numParticle; i++) {
    if ( posX[i] > width - radius[i] || posX[i] < radius[i] ) dirX[i] = -dirX[i];
    if ( posY[i] < radius[i] || posY[i] > height - radius[i]) dirY[i] = -dirY[i];
  }
}

```

but that is not the only problem,  
[https://processing.org/reference/ellipse\_.html](https://processing.org/reference/ellipse_.html)  
width height means DIAMETER  
and edge check need RADIUS

```auto
    ellipse(posX[i], posY[i], 2*radius[i], 2*radius[i]);

```

* * *

random usage:

```auto
    radius[i] = int(random(100));

```

would allow from 0 … 99 ( 198 diameter )  
better give a low range

```auto
    radius[i] = int(random(10,50));

```

and if you use that on the color too,  
can create/adjust a kind of color theme: “soft”-theme

```auto
    randomColor[i] = color(random(100,200), random(100,200), random(100,200));

```
