PDA

View Full Version : Need help!!

LSn145
10-04-2011, 09:00 PM
So let us say that I have an Array:
int maxSize = 9;
int arr[][][][] = new int[maxsize][maxSize][25][19]

This works great...
But I need to use negative values like:
chunkX = -1
chunkY = -1
arr[chunkX][chunkY][12][9] = 0

but the array doesn't work that way.

It's for a coordinate system that has to be able to have negative values in the chunkX/Y variables.

More on the array:
"maxSize" is the maximum chunks,
each chunk has 25*19 coordinates that includes a value ranging between 0 and maximum(where maximum is currently 1)
the chunk arr[0][0] is equal to two more arrays that contains the values between 0-1, and there are a total of 475 coordinates in each chunk that must be filled.
But the chunkX and chunkY must be able to go to minus...

It doesn't have to be an array...

Any help are much appreciated :)

alykins
10-04-2011, 10:19 PM
no clue what language you are in but you are setting up jagged arrays (if your in C# anyways) so for your example using the chunks you would have

arr[-1][-1][12][9]

meaning

arr[-1 deep][-1 deep][12 deep][9 deep]

and since arrays start at 0 and not negative you cannot have a -1 in the declaration... you can have values set to be negative values, but not negative dimensions

LSn145
10-04-2011, 10:58 PM
no clue what language you are in but you are setting up jagged arrays (if your in C# anyways) so for your example using the chunks you would have

arr[-1][-1][12][9]

meaning

arr[-1 deep][-1 deep][12 deep][9 deep]

and since arrays start at 0 and not negative you cannot have a -1 in the declaration... you can have values set to be negative values, but not negative dimensions

yeah, but I need an alternative to arrays.
Like a class or something, I'm using Java BTW.
Already knew that, But thanks anyways

the thing is I can use the 0 to 9.
I need to store the negatives the same way.
So I might try to use another array called negativeArray or something

I'll post the code when(if at all) I'm done.

alykins
10-04-2011, 11:53 PM
you can store a negative number in the array, you need to declare the array first

int myArray[4] = new int[4];
myArray[4]={-3, -15, 0, 45};

sfg
10-05-2011, 04:57 AM
You could try an offset in these cases. Identify a middle and offset as necessary.

int mid = 5;

myarray[mid-offset][mid-offset][0][0] = value;

LSn145
10-05-2011, 11:51 AM
yeah,
since the Array is constantly expanding,
I cannot use it like this.

But my plan is this:

//UpperLeft
ulArr[][][][]

//UpperRight
urArr[][][][]

//LowerLeft
llArr[][][][]

//LowerRight
lrArr[][][][]