# Can't create 2D array

**URL:** <https://discourse.processing.org/t/cant-create-2d-array/36894>\
**Category:** Beginners\
**Created:** [May 15, 2022, 9:59am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894 "2022-05-15T09:59:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tensor](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tensor](https://discourse.processing.org/u/tensor)\
**Post date:** [May 15, 2022, 9:59am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/1 "2022-05-15T09:59:49Z")

</div>

```auto
PVector pos;
float yaw;
float pitch;
float roll;
float[][] rmx;
PVector posinit;

void setup() {

  size(640, 360, P3D);
  pos = new PVector(width/2, height/2, 0);
  posinit = new PVector(width/2, height/2, 0);
  yaw = PI/8;
  pitch = PI/12;
  roll = PI/10;
  rmx = {{cos(yaw)*cos(pitch), cos(yaw)*sin(pitch)*cos(roll) - sin(yaw)*cos(roll), cos(yaw)*sin(pitch)*cos(roll) + sin(yaw)*sin(roll) },
         {sin(yaw)*cos(pitch), sin(yaw)*sin(pitch)*sin(roll) + cos(yaw)*cos(roll), sin(yaw)*sin(pitch)*cos(roll) - cos(yaw)*sin(roll) },
         {-sin(pitch), cos(pitch)*sin(roll), cos(pitch)*cos(roll)}};
}

```

it shows me an error called “bad identifier” at line where i put the values for “rmx”

---

<div class="post-metadata">

**Author:** ![tensor](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tensor](https://discourse.processing.org/u/tensor)\
**Post date:** [May 15, 2022, 10:03am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/2 "2022-05-15T10:03:37Z")

</div>

my apologies if its something stupid

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 15, 2022, 10:19am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/3 "2022-05-15T10:19:17Z")

</div>

Hello,

Consider:

```auto
  rmx = new float [] [] 
         {
         {cos(yaw)*cos(pitch), cos(yaw)*sin(pitch)*cos(roll) - sin(yaw)*cos(roll), cos(yaw)*sin(pitch)*cos(roll) + sin(yaw)*sin(roll) },
         {sin(yaw)*cos(pitch), sin(yaw)*sin(pitch)*sin(roll) + cos(yaw)*cos(roll), sin(yaw)*sin(pitch)*cos(roll) - cos(yaw)*sin(roll) },
         {-sin(pitch), cos(pitch)*sin(roll), cos(pitch)*cos(roll) } 
         };

```

I looked for some references on initializing an array and found this:

> **[How to Declare and Initialize an Array in Java](https://stackabuse.com/how-to-declare-and-initialize-an-array-in-java/)**
>
> In this article, we'll go over how to declare and initialize an array in Java, with examples and best practices. We'll cover traditional array declaration and initialization, as well as IntStreams.

`:)`

---

<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:** [May 15, 2022, 10:47am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/4 "2022-05-15T10:47:47Z")

</div>

Dunno might be that this only works outside any function

---

<div class="post-metadata">

**Author:** ![tensor](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tensor](https://discourse.processing.org/u/tensor)\
**Post date:** [May 15, 2022, 10:49am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/5 "2022-05-15T10:49:18Z")

</div>

thanks fam it worked

i just had to initialize it once outside setup() and then put the values like you did inside the setup

---

<div class="post-metadata">

**Author:** ![tensor](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tensor](https://discourse.processing.org/u/tensor)\
**Post date:** [May 15, 2022, 10:50am UTC](https://discourse.processing.org/t/cant-create-2d-array/36894/6 "2022-05-15T10:50:24Z")

</div>

its weird that if i do the entire array thing outside setup then it doesnt give me error but doesnt work either
