|
-
Apr 18th, 2005, 03:39 PM
#1
Thread Starter
Lively Member
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
-
Apr 18th, 2005, 03:43 PM
#2
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
-
Apr 18th, 2005, 03:55 PM
#3
Thread Starter
Lively Member
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
-
Apr 18th, 2005, 04:07 PM
#4
Fanatic Member
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:
'your type
Private Type myType
A As Long
B As Long
C As Long
End Type
'my array
Dim myArray(10,10,10) As myType
'Then to access them it's like this:
myArray(0,0,0).A = 0
myArray(0,0,0).B = 16
myArray(0,0,0).C = 54
'etc...
-
Apr 18th, 2005, 04:13 PM
#5
Thread Starter
Lively Member
Re: Using a 3D array as a map
Thanks, i think that should work. I'll see how it goes
-
Apr 18th, 2005, 04:41 PM
#6
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?
-
Apr 18th, 2005, 04:49 PM
#7
Fanatic Member
Re: Using a 3D array as a map
 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!?!?!
-
Apr 19th, 2005, 01:21 AM
#8
Frenzied Member
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'.
-
Apr 19th, 2005, 03:48 AM
#9
Thread Starter
Lively Member
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
-
Apr 19th, 2005, 04:16 AM
#10
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|