Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Need help!!

  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Need help!!

    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

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    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
    Code:
    arr[-1][-1][12][9]
    meaning
    Code:
    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

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by alykins View Post
    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
    Code:
    arr[-1][-1][12][9]
    meaning
    Code:
    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.

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    you can store a negative number in the array, you need to declare the array first
    Code:
    int myArray[4] = new int[4];
    myArray[4]={-3, -15, 0, 45};

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    sfg
    sfg is offline
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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[][][][]


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •