# Error message in this Array problem i don't know how to resolve

**URL:** <https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611>\
**Category:** Coding Questions\
**Created:** [April 24, 2019, 10:04pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611 "2019-04-24T22:04:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [April 24, 2019, 10:04pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/1 "2019-04-24T22:04:20Z")

</div>

In Dan Shiffman’s book **Learning Processing** , p. 179, example 9-10

I have typed in the code for this example, and have carefully checked to make sure no keystroking errors. However I keep getting errors in the void rollover() function area. I think there’s an extra curly bracket but it matches the code in the book.

* * *

```auto
Stripe[] stripes = new Stripe[10];

void setup() {
  size(200, 200);
  for (int i = 0; i<stripes.length; i++) {
    stripes[i] = new Stripe();
  }
}
void draw() {
  background(100);
  for (int i =0; i < stripes.length; i++) {
    stripes[i].rollover(mouseX, mouseY);
    stripes[i].move();
    stripes[i].display();
  }
}
class Stripe {
  float x;
  float y;
  float w;
  boolean mouse;

  Stripe() {
    x = 0;
    speed = random(1);
    w = random(10, 30);
    mouse = false;
  }

  void display() {
    if (mouse) {
      fill(255);
    } else {
      fill(255, 100);
    }
    noStroke();
    rect(x, 0, w, height);
  }
void move() {
  x += speed;
  if (x > width + 20) x =-20;
}

void rollover(int mx, int my) { 
  {
    //left edge is x, right edge is x + w
    if (mx > x && mx < x + w)
      mouse = true;
  } else {
    mouse = false;
  }
}
}

```

---

<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:** [April 24, 2019, 10:48pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/2 "2019-04-24T22:48:41Z")

</div>

to find those: click ctrl-t in processing to get auto-indents

often we can spot the error then

error was:

```auto
void rollover(int mx, int my) {
{

```

speed was not defined

```auto

Stripe[] stripes = new Stripe[10];

void setup() {
  size(200, 200);
  for (int i = 0; i<stripes.length; i++) {
    stripes[i] = new Stripe();
  }
}
void draw() {
  background(100);
  for (int i =0; i < stripes.length; i++) {
    stripes[i].rollover(mouseX, mouseY);
    stripes[i].move();
    stripes[i].display();
  }
}

// ====================================================

class Stripe {
  float x;
  float y;
  float w;
  float speed; 
  boolean mouse;

  // constr 
  Stripe() {
    x = 0;
    speed = random(1);
    w = random(10, 30);
    mouse = false;
  }

  void display() {
    if (mouse) {
      fill(255);
    } else {
      fill(255, 100);
    }
    noStroke();
    rect(x, 0, w, height);
  }
  void move() {
    x += speed;
    if (x > width + 20) x =-20;
  }

  void rollover(int mx, int my) {
    //left edge is x, right edge is x + w
    if (mx > x && mx < x + w) {
      mouse = true;
    } else {
      mouse = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [April 24, 2019, 11:05pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/3 "2019-04-24T23:05:19Z")

</div>

I have now defined the speed, but am still receiving the same error message:

Stripe[] stripes = new Stripe[10];

void setup() {  
size(200, 200);  
for (int i = 0; i\<stripes.length; i++) {  
stripes[i] = new Stripe();  
}  
}  
void draw() {  
background(100);  
for (int i =0; i \< stripes.length; i++) {  
stripes[i].rollover(mouseX, mouseY);  
stripes[i].move();  
stripes[i].display();  
}  
}

class Stripe {  
float x;  
**float speed;**  
float w;  
boolean mouse;

Stripe() {  
x = 0;  
speed = random(1);  
w = random(10, 30);  
mouse = false;  
}

void display() {  
if (mouse) {  
fill(255);  
} else {  
fill(255, 100);  
}  
noStroke();  
rect(x, 0, w, height);  
}

void move() {  
x += speed;  
if (x \> width + 20) x =-20;  
}

void rollover(int mx, int my) {  
{  
//left edge is x, right edge is x + w  
if (mx \> x && mx \< x + w)  
mouse = true;  
} else {  
mouse = false;  
}  
}  
}

---

<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:** [April 24, 2019, 11:28pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/4 "2019-04-24T23:28:08Z")

</div>

> [@Chrisir](#):
>
> void rollover(int mx, int my) { {

One { too many

Okay…?

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [April 24, 2019, 11:48pm UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/5 "2019-04-24T23:48:08Z")

</div>

I tried deleting that second bracket, but still an error message: “expecting {, found ‘else’”

I think there may be a typo in the Shiffman book?

**UPDATE TO POST**  
Confirming there is a typo in this code in the Shiffman book.  
Placement of brackets sh’d be:

```auto
void rollover(int mx, int my) {
    if (mx > x && mx < x + w) {
      mouse = true;
    } else {
      mouse = false;
    }
}

```

---

<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:** [April 25, 2019, 8:11am UTC](https://discourse.processing.org/t/error-message-in-this-array-problem-i-dont-know-how-to-resolve/10611/6 "2019-04-25T08:11:11Z")

</div>

Congrats! You solved it!
