3-D array question

BlitzMax Forums/BlitzMax Beginners Area/3-D array question

QuickSilva(Posted 2009) [#1]
Please could somebody tell me how many position the following array can hold?

Name$(2,4,2)

Am I correct in saying 26? I`m not sure if I understand things properly so I would like to check.

Thanks,

Jason.


Brucey(Posted 2009) [#2]
2 x 4 x 2 = 16


QuickSilva(Posted 2009) [#3]
This is how I`m seeing it,

name$(1,1,1)=""
name$(1,2,1)=""
name$(1,3,1)=""
name$(1,4,1)=""

name$(1,1,2)=""
name$(1,2,2)=""
name$(1,3,2)=""
name$(1,4,2)=""

name$(2,1,1)=""
name$(2,2,1)=""
name$(2,3,1)=""
name$(2,4,1)=""

name$(2,1,2)=""
name$(2,2,2)=""
name$(2,3,2)=""
name$(2,4,2)=""


So basically these are all available positions in my array. Is this correct? I`m not sure what I was thinking before...

Jason.


Brucey(Posted 2009) [#4]
You know that Arrays [ ] are zero indexed ?

so... an array[2] has indexes 0 and 1.


QuickSilva(Posted 2009) [#5]
Yes, I just find it easier to visualize starting from 1. Must break that habit.

Thanks for the help.

Jason.


GfK(Posted 2009) [#6]
I'm intrigued - how did you arrive at 26??


QuickSilva(Posted 2009) [#7]
I was trying to visualize it like this,



then I counted down each column to try to figure out how many locations I had to store values in. So first column, 1 and 2, second column, 1,2,3,4 and finally third column, 1,2 1,2 1,2 1,2 twice giving a grand total of 26.

Arrays are one of those things that I`ve always had problems visualizing especially 3 dimensional arrays.

I still have trouble with them as you can see.

I find most explanations of them extremely confusing. It would be nice to see a simple explantion on them.

Jason.


TaskMaster(Posted 2009) [#8]
Just multiply the number of all the dimensions together.

For instance: Name$(2,4,2) = 2x4x2=16.

Name$(0,0,0)
Name$(0,0,1)
Name$(0,1,0)
Name$(0,1,1)
Name$(0,2,0)
Name$(0,2,1)
Name$(0,3,0)
Name$(0,3,1)
Name$(1,0,0)
Name$(1,0,1)
Name$(1,1,0)
Name$(1,1,1)
Name$(1,2,0)
Name$(1,2,1)
Name$(1,3,0)
Name$(1,3,1)

Actually, it is just like counting in a base 10 system, but instead of each digit going to 10, they only go as high as the number of elements in that position.