# Trouble on array's \[COMPLICATED\]

**URL:** <https://discourse.processing.org/t/trouble-on-arrays-complicated/15496>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 14, 2019, 7:22pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496 "2019-11-14T19:22:14Z")\
**Posts on this page:** 8\
**Page:** 2

<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 23, 2019, 8:14am UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/21 "2019-11-23T08:14:50Z")

</div>

**First** , we want to correct this issue:

> [@Chrisir](#):
>
> however it doesn’t for any other circle

I told you what to do. Does your `println()` come out now?

* * *

**Second** , we want to color the column. I have given you code for this to. Do you know where it belongs into your code?

> [@IsaiahZ](#):
>
> how must I state ‘i’

The i comes from the for-loop.

I think you can figure this out now.

---

<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 23, 2019, 10:15am UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/22 "2019-11-23T10:15:22Z")

</div>

i think one problem might be if  
you want the column select circles  
and the row select circles  
as 2 independent option groups ( only one of them can be selected )  
also should be possible to UNSELECT them too.

here independent from the rect array / palette select i made in your last post:

a new circle class what knows its own array and can do the option group internally.

```auto
int xC = 60, yC = 80, dC = 15;
int off=20, w = 23, rows = 12, cols = 8;
int selR,selC;

Circle[] row = new Circle[rows];
Circle[] col = new Circle[cols];

void setRow() {
  for (int i = 0; i < row.length; i++)
    row[i] = new Circle(xC, yC+i*w, dC, i,row);
}

void setCol() {
  for (int i = 0; i < col.length; i++)
    col[i] = new Circle(off+xC+i*w, yC-off, dC, i,col);
}

void drawRow() {
  for (int i = 0; i < row.length; i++)
    row[i].display();
}

void drawCol() {
  for (int i = 0; i < col.length; i++)
    col[i].display();
}

class Circle {
  float xC, yC, dC;
  boolean sel=false;
  int idx;
  Circle[] me;
  
  Circle(float _xC, float _yC, float _dC, int _idx, Circle[] _me) {
    xC = _xC;
    yC = _yC;
    dC = _dC;
    idx = _idx;
    me = _me;
  }

  void display() {
    sel();
    push();
    strokeWeight(1);
    stroke(200, 200, 200);
    if (over()) {
      strokeWeight(3);
      stroke(200, 0, 0);
    }
    if ( sel ) fill(200, 0, 0);
    else fill(0);
    circle(xC, yC, dC);
    pop();
  }

  boolean over() {
    return( dist(mouseX, mouseY, xC, yC) < dC/2 );
  }

  void sel() {
    if (over() && !sel ) {
      if (mousePressed && mouseButton == LEFT) {
        sel=true;        
        for ( int i =0; i < me.length;i++ ) if ( i != idx ) me[i].sel=false; // option group reset all others of my group
        println("sel: "+idx);
      }
    }
    if (over() && sel ) {
      if (mousePressed && mouseButton == RIGHT) {
        sel=false;
        println("UNsel: "+idx);
      }
    }
  }
}

void check_RC() {
  selR = -1;
  for (int i = 0; i < row.length; i++) if ( row[i].sel ) selR = i;
  selC = -1;
  for (int i = 0; i < col.length; i++) if ( col[i].sel ) selC = i;
}

// _______________________________________ main selector tool
void setup() {
  size(500, 500);
  setRow();
  setCol();
  println("use: mouse click LEFT select RIGHT unselect\nkey [t] for print");
}

void draw() {
  background(0);
  drawRow();
  drawCol();
  check_RC(); // check row and col array and set globals 
}

void keyPressed() {
  if ( key == 't' ) println("sel: row "+selR+", col "+selC);
}

```

---

<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 23, 2019, 2:06pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/23 "2019-11-23T14:06:58Z")

</div>

@kll: thanks for interrupting

why do you post a full code when I am trying to lead him there?

Your order of code is off. The correct way is

- vars, then setup and draw, functions, classes

Chrisir

---

<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 23, 2019, 2:11pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/24 "2019-11-23T14:11:51Z")

</div>

no problem you can repair it and talk him through / or make steps,

what i needed to mention was that option group thing,  
( as a optional problem )  
so first OP must define the real operation function of that  
two circle buttons rows  
can / must there one col and one row be selected?  
can there be more selected?  
depending on that my idea can be ignored.

otherwise

```auto
for ( int i =0; i < me.length;i++ ) if ( i != idx ) me[i].sel=false;

```

will work, but how it can be teached?

---

<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 23, 2019, 2:13pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/25 "2019-11-23T14:13:32Z")

</div>

I appreciate this.

Thank you!

Greetings!

---

<div class="post-metadata">

**Author:** ![IsaiahZ](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@IsaiahZ](https://discourse.processing.org/u/IsaiahZ)\
**Post date:** [November 25, 2019, 3:22pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/26 "2019-11-25T15:22:14Z")

</div>

Thank you all. This was very helpful. I think I’m starting to understand it all. I very much enjoyed being lead through this by you. Thank you Chrisir and kll for your guidance.

---

<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 25, 2019, 3:36pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/27 "2019-11-25T15:36:12Z")

</div>

But did you solve it?

Do both row of circles mark the entire row or column respectively?

Shall I post my way?

---

<div class="post-metadata">

**Author:** ![IsaiahZ](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@IsaiahZ](https://discourse.processing.org/u/IsaiahZ)\
**Post date:** [November 25, 2019, 3:39pm UTC](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496/28 "2019-11-25T15:39:03Z")

</div>

I have it almost solved but I believe my understanding of it due to yours and kll’s explanation I believe I can figure the rest out on my own. Thank you though. If I do run into any other problems I’ll be sure to let you know!

[Previous page](https://discourse.processing.org/t/trouble-on-arrays-complicated/15496.md?page=1)
