# I can't figure out how to make this array compatible with my Button class

**URL:** https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403
**Category:** Coding Questions
**Created:** [October 23, 2022, 7:44pm UTC](https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403 "2022-10-23T19:44:14Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![darthbray](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@darthbray](https://discourse.processing.org/u/darthbray)
#### Post date: [October 23, 2022, 7:44pm UTC](https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403/1 "2022-10-23T19:44:14Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I’m trying to create a randomly generated chord progression program but I haven’t even reached that part yet, I’m stuck on making an array with my button class. The error message is “Type mismatch: cannot convert from sketch\_221023a.Button to int,” which doesn’t make sense because I’ve followed 3 tutorials on how to implement arrays into classes and I don’t see what’s wrong. (please excuse some redundancies and messy attempted solutions, I’ve been trying to bugfix this for the past hour)

```auto
//library imports
import wellen.*;
//tips for using wellen
//Tone.note_on(x,y) | creates a note, x being the pitch and y being the velocity. Pitch is between 0-127. Velocity is 0-100.
//Tone.note_off(x,y) | will turn off matching tones
//Tone.is_playing() ? x : y | detects if a note is playing, will give x if yes or y if no
//Scale.HALF_TONE, this defines the scale for an int, half tone is the scale of all tones
//Scale.get_note(x, y, z) | x is the scale used, y is the root note, z is the steps up from the root note in accordance with the scale
Button resetbutton;
int screenx = 800;
int screeny = 800;
//screenx and y because size doesn't take floats
int sy;
int sx;
int numButton = 1;
int buttonWidth;
int buttonHeight;
String[] text = {"1","2","3","4"};
int[] buttons = new int[50];
int colorR;
int colorG;
int colorB;
Button ba;

void settings() {
  sx = screenx;
  sy = screeny;
  for (int i = 0; i < 4; i ++)
  {
      buttons[i] = new Button(0+(sx/numbutton), 0+(sy/numbutton), buttonWidth, buttonHeight, text, buttonColor, colorR, colorG, colorB);
      numButton = numButton++;
  }
  size(screenx, screeny);
}

void setup() {
}

void draw() {
  ba = new Button(0+(sx/numButton), 0+(sy/numButton), buttonWidth, buttonHeight, "hi", colorR, colorG, colorB);
  background(255);
  fill(0);
  println(screenx+ screeny);

  // buttons.update
  // buttons.render
}

void mousePressed() {
  Tone.note_on(50, 100);
}

```

here is the class code

```auto
class Button
{
  PVector Pos = new PVector(0, 0);
  float Width = 0;
  float Height = 0;
  color Color;
  String Text;
  boolean Pressed = false;
  boolean Clicked = false;
  // Constructor to create button
  Button(int x, int y, int w, int h, String t, int r, int g, int b)
  {
    Pos.x = x;
    Pos.y = y;
    Width = w;
    Height = h;
    Color = color(r, g, b);
    Text = t;
  }
  void update() //must be place in draw in order to work
  {
    if (mousePressed == true && mouseButton == LEFT && Pressed == false)
    {
      Pressed = true;
      if (mouseX >= Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height)
      {
        Clicked = true;
      }
    } else {
      Clicked = false;
      Pressed = false;
    }
  }
  void render() //must be place in draw to render on screen
  {
    fill(Color);
    rect(Pos.x, Pos.y, Width, Height);

    fill(0);
    textAlign(CENTER, CENTER);
    text(Text, Pos.x+(Width/2), Pos.y+(Height/2));
  }
  boolean IsClicked()//used in if statements to check if button has been clicked
  {
    return Clicked;
  }
}

```

if anybody can help I’d super super appreciate it!

---

<div class="post-metadata">

### Author: ![darthbray](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@darthbray](https://discourse.processing.org/u/darthbray)
#### Post date: [October 23, 2022, 7:47pm UTC](https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403/2 "2022-10-23T19:47:43Z")

</div>

a little update I added this code

Button buttons = new Button[50];

it did not change the result

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [October 23, 2022, 10:43pm UTC](https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403/3 "2022-10-23T22:43:16Z")

</div>

Hi there Dartbray, you’re close with your little update.

The problem is that you _declare_ it to be of type `Button` (singular), yet you _initialize_ it with `new Button[50]` (array). Simply change it into:

```auto
Button[] buttons = new Button[50];

```
