Results 1 to 10 of 10

Thread: Using a 3D array as a map

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Question Using a 3D array as a map

    Hi, I want to use a 3d array to act as a map. I have more than one integer that I need to store in a single elemnt of the array, for example I want element [0],[0],[0] to hole values 0,16 and 54. Is this possible to do and if so, can the integers be accessed seperatley at a later date?

    Thanks

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Using a 3D array as a map

    Nope. In a three dimensional array, each set of three array variable equate to only ONE number. a(1,2,3) = 35

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Re: Using a 3D array as a map

    If I stored the numbers as a string, a(0,0,0) = "0,23,50" and used the comma as a delimeter would that work. If this would work then would it make a signifficant difference in time, to seperate the string and then use each value?

    Also, is there a way to store for example a memory location, or a suitable type of location in the array, and then in this location store a set of integers?

    thanks

  4. #4
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Using a 3D array as a map

    You could create a user-defined type to hold multiple values and then have an array of those.

    example:
    VB Code:
    1. 'your type
    2. Private Type myType
    3.   A As Long
    4.   B As Long
    5.   C As Long
    6. End Type
    7.  
    8. 'my array
    9. Dim myArray(10,10,10) As myType
    10.  
    11. 'Then to access them it's like this:
    12. myArray(0,0,0).A = 0
    13. myArray(0,0,0).B = 16
    14. myArray(0,0,0).C = 54
    15.  
    16. 'etc...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Re: Using a 3D array as a map

    Thanks, i think that should work. I'll see how it goes

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Using a 3D array as a map

    Wouldn't X,Y, and Z make more sense than A,B and C since he's doing a map in an array?

  7. #7
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Using a 3D array as a map

    Quote Originally Posted by Jacob Roman
    Wouldn't X,Y, and Z make more sense than A,B and C since he's doing a map in an array?
    Was just an example. He said he wanted to put 3 numbers in against a map co-ordinate. For all i know he's storing the value of gold, silver and bronze at that location!?!?!

  8. #8
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Using a 3D array as a map

    You could also make it a 4D array.
    Array(x,y,z,2) will let you store three items per 'cube'.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    67

    Re: Using a 3D array as a map

    Could you explain how I would store 3 items in a 4d array.

    Would it be for example

    a(x,y,z,1) = 12
    a(x,y,z,2) = 30
    a(x,y,z,3) = 45 etc...

    Thanks

  10. #10
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Using a 3D array as a map

    That would be how you do it.

    The only issue is that the items you are storing must be the same data type as the array. ie. If you declare it as Dim a(10,10,10,10) As Integer then ALL values must be an Integer.

    If all being the same datatype is ok, then I would use the 4D array.

Posting Permissions

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



Click Here to Expand Forum to Full Width