# arrays in functions

## Recommended Posts

I should probably delete it in like an hour just in case someone was suckered into spending time replying to it, in case they're in the middle of typing something.

Hello and welcome to another edition of gez solves my problems.

f2 is a global array. I want to rotate f2 into f3 counter clockwise, preferably using a function so any similar array can be rotated into any other, so I can be lazy and not "redraw" f3.

```int f2[15][15] = {
{0,0,1,2,3,4,5,6,7,7,7,7,7,7,7},
{0,0,1,2,3,4,5,6,7,7,7,7,7,7,7},
{1,1,1,2,3,4,5,6,7,7,7,7,7,7,7},
{2,2,2,2,3,4,5,6,7,7,7,7,7,7,7},
{3,3,3,3,3,4,5,6,7,7,7,7,7,7,7},
{4,4,4,4,4,4,5,6,7,7,7,7,7,7,7},
{5,5,5,5,5,5,5,6,7,7,7,7,7,7,7},
{6,6,6,6,6,6,6,6,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}};
int f3[15][15];

function int ccwRotate (int base, int target)
{
int bx = 0;
int by = 0;
int tx = 0;
int ty = 14;
for(by=0;by<15;by+=1)
{
for(bx=0;bx<15;bx+=1)
{
target[ty][tx] = base[by][bx];
ty-=1;
}
tx+=1;
}
}
```
but it says target and base aren't arrays, and yada yada yaaaaw. (don't even know if that function would work correctly because couldn't test due to errors) Tried putting base[15][15] as a parameter but it was still gheying me with ghey.

I "solved" it, but its ugly, copy-pasted hard to reuse code/ not a function. The places where I wrote "//first rotation... //second rotation... etc" seem like a place where similar code should be wrapped into a function. But I guess you can't because arrays suck in functions.

```#include "zcommon.acs"

int lights[8] = {96,112,128,144,160,176,192,208};

int f1[15][15] = {
{6,5,4,3,2,1,0,0,0,1,2,3,4,5,6},
{7,6,5,4,3,2,1,0,1,2,3,4,5,6,7},
{7,7,6,5,4,3,2,1,2,3,4,5,6,7,7},
{7,7,7,6,5,4,3,2,3,4,5,6,7,7,7},
{7,7,7,7,6,5,4,3,4,5,6,7,7,7,7},
{7,7,7,7,7,6,5,4,5,6,7,7,7,7,7},
{7,7,7,7,7,7,6,5,6,7,7,7,7,7,7},
{7,7,7,7,7,7,7,6,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}};
int f2[15][15] = {
{0,0,1,2,3,4,5,6,7,7,7,7,7,7,7},
{0,0,1,2,3,4,5,6,7,7,7,7,7,7,7},
{1,1,1,2,3,4,5,6,7,7,7,7,7,7,7},
{2,2,2,2,3,4,5,6,7,7,7,7,7,7,7},
{3,3,3,3,3,4,5,6,7,7,7,7,7,7,7},
{4,4,4,4,4,4,5,6,7,7,7,7,7,7,7},
{5,5,5,5,5,5,5,6,7,7,7,7,7,7,7},
{6,6,6,6,6,6,6,6,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7},
{7,7,7,7,7,7,7,7,7,7,7,7,7,7,7}};
int f3[15][15];
int f4[15][15];
int f5[15][15];
int f6[15][15];
int f7[15][15];
int f8[15][15];
script 1 open
{
//first rotation into f3
int bx = 0;
int by = 0;
int tx = 0;
int ty = 14;
for(by=0;by<15;by+=1)
{
ty=14;
for(bx=0;bx<15;bx+=1)
{
f3[ty][tx] = f2[by][bx];
ty-=1;
}
tx+=1;
}

//second rotation into f4
tx=0;
for(by=0;by<15;by+=1)
{
ty=14;
for(bx=0;bx<15;bx+=1)
{
f4[ty][tx] = f3[by][bx];
ty-=1;
}
tx+=1;
}

//third rotation into f5
tx=0;
for(by=0;by<15;by+=1)
{
ty=14;
for(bx=0;bx<15;bx+=1)
{
f5[ty][tx] = f4[by][bx];
ty-=1;
}
tx+=1;
}

delay(100);
int y=0;
for(y=0;y<15;y+=1)
{
print(d:f5[y][0],d:f5[y][1],d:f5[y][2],d:f5[y][3],d:f5[y][4],d:f5[y][5],d:f5[y][6],d:f5[y][7],d:f5[y][8],d:f5[y][9],d:f5[y][10],d:f5[y][11],d:f5[y][12],d:f5[y][13],d:f5[y][14],s:"   ",d:y);
delay(35);
}
}
```

Damn, dude. That's all I can really say :P

You can delete this topic if you want, since you're like, a "moderator".
I might find your "skank" hash useful which you mentioned in that linked topic btw. Good thing I have a memory to even remember info from past topics I made.

## Create an account

Register a new account