# Cannot invoke movingstuff() on the array type anarray.shapes\[\]

**URL:** https://discourse.processing.org/t/cannot-invoke-movingstuff-on-the-array-type-anarray-shapes/43603
**Category:** Coding Questions
**Created:** [January 2, 2024, 1:39am UTC](https://discourse.processing.org/t/cannot-invoke-movingstuff-on-the-array-type-anarray-shapes/43603 "2024-01-02T01:39:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@Charlie1](https://discourse.processing.org/u/Charlie1)
#### Post date: [January 2, 2024, 1:39am UTC](https://discourse.processing.org/t/cannot-invoke-movingstuff-on-the-array-type-anarray-shapes/43603/1 "2024-01-02T01:39:41Z")

</div>

Hey Guys, do you know of a way I can overcome this error? Thanks.  
//shapes shapedimentions = new shapes[2];  
//squares squaredimentions = new squares[2];  
shapes anyshapevariable = new shapes[4];

void setup() {

size(500, 400);  
for (int i = 0; i \< anyshapevariable.length; i++){  
anyshapevariable[i] = new squares(40,0);

}  
//shapedimentions[0]= new shapes(33);  
//shapedimentions[1] = new shapes(50);  
//squaredimentions[0] = new squares(30,50);  
//squaredimentions[1] = new squares(30,90);

}  
int u = 0;

void draw() {  
background(255);  
int i;

//if (u\>=0&&u\<5){  
// u++;  
//for (i = 0; i \< shapedimentions.length; i++) {  
// shapedimentions[i].myshapyshenanigans();  
// squaredimentions[i].mysquaryshenanigans();  
//}}  
for ( shapes shape : anyshapevariable ) {  
anyshapevariable.movingstuff();  
//}  
}}

abstract class shapeystuff{  
int x;  
int y;  
}

class shapes extends shapeystuff {  
shapes(int x2) {  
x = x2;  
}

void myshapyshenanigans() {  
circle(x, 50, 30);  
}  
int y;

}

class square extends shapeystuff{

square(int x2, int y2) {  
//still not 100% how this works.  
y = y2;  
x = x2;

}  
void mysquaryshenanigans(){  
square(x,y,50);  
}

}

---

<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: [January 8, 2024, 5:23pm UTC](https://discourse.processing.org/t/cannot-invoke-movingstuff-on-the-array-type-anarray-shapes/43603/2 "2024-01-08T17:23:50Z")

</div>

> [@Charlie1](#):
>
> ```auto
> for ( shapes shape : anyshapevariable ) { // for each shape in anyshapevariable do something 
> anyshapevariable.movingstuff();
> 
> ```

- this can’t work, because with `anyshapevariable.movingstuff();` you refer to `anyshapevariable` (an array) but you need to refer to _shape_ which is the for-loop-variable

- you haven’t defined a function `movingstuff()`; in the class that’s why he can’t invoke it

- the for-loop reads: for each shape in anyshapevariable do something by the way

**Problem**

> [@Charlie1](#):
>
> `anyshapevariable[i] = new squares(40,0);`

This line won’t work because anyshapevariable is of type shapes not squares.

Consider `anyshapevariable[i] = new shapes(40, 0);`

**Remarks**

- anyshapevariable is not a good name. It sounds like a variable but is a list of shapes.
- shapes is not a good name, it suggests plural but it’s only one shape
- class name are starting with a Capital letter (convention)

* * *

**Example:**

```auto

// Demo for classes

//shapes shapedimentions = new shapes[2];
//squares squaredimentions = new squares[2];

shapes[] anyshapevariable = new shapes[4];
int u = 0;

void setup() {
  size(500, 400);

  for (int i = 0; i < anyshapevariable.length; i++) {
    anyshapevariable[i] = new shapes(40, 0);
  }
  //shapedimentions[0]= new shapes(33);
  //shapedimentions[1] = new shapes(50);
  //squaredimentions[0] = new squares(30,50);
  //squaredimentions[1] = new squares(30,90);
}

void draw() {
  background(255);
  int i;

  //if (u>=0&&u<5){
  // u++;
  //for (i = 0; i < shapedimentions.length; i++) {
  // shapedimentions[i].myshapyshenanigans();
  // squaredimentions[i].mysquaryshenanigans();
  //}}
  for ( shapes shape : anyshapevariable ) {
    shape.movingstuff();
  }
}

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

abstract class shapeystuff {
  int x;
  int y;

  void movingstuff() {
    square(x, y, 50);
    x++;
  }
}

class shapes extends shapeystuff {
  shapes(int x2) {
    x = x2;
  }

  shapes(int x2, int y2) { // ????
    x = x2;
  }

  void myshapyshenanigans() {
    circle(x, 50, 30);
  }
  int y;
}

class square extends shapeystuff {

  square(int x2, int y2) {
    //still not 100% how this works.
    y = y2;
    x = x2;
  }
  void mysquaryshenanigans() {
    square(x, y, 50);
  }
}
//

```
