Multidimensional Arrays
Author |
Message |
TheEvilOne
|
Posted: Tue Apr 26, 2005 9:23 am Post subject: Multidimensional Arrays |
|
|
Well... im back to ask another of my stupid questions. I asked my teacher, but he wasnt that much help =/
What im trying to do is make a multidimensional array. Such that:
code: |
inside array
1|123456
2|123456
outside array 3|123456
4|123456
5|123456
6|123456
|
what im trying to do is hold the data of placed tiles. So let's say you clicked in the bottom left corner, and your map was 6x6 tiles big, it would turn outside array(6) inside array (1) to true.
I'm also trying to make the size of the arrays dynamic. Reason is... when you create a new map, it has to size the array depending on the size of your map. A 6x6 map will have 36 array slots.
If there is no way to create new array slots on a multidimensional array, then I guess ill just have to do it with multiple slots in the same array. as in:
code: |
1 2 3 4 5 6
7 8 9 10 11 12
etc
|
If anyone can help me on either of these ways, it would be greatly appreciated... and if what I just asked sounds really stupid... just ask me to explain better |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Tue Apr 26, 2005 11:02 am Post subject: (No subject) |
|
|
You can't use flexible arrays with multi-dimensional arrays, fully. I believe you can use the first dimension of the array as flexible, but not the second or any later dimensions.
You might be able to make a row class and have a flexible array of the row class, but that's probably not going to be too clean.
If you want a basic 2d array:
code: |
var myArray : array lowerBounds .. upperBounds, lowerBounds .. upperBounds of typeSpec
|
|
|
|
|
|
|
Bacchus
|
Posted: Tue Apr 26, 2005 6:39 pm Post subject: (No subject) |
|
|
accually Cervantes, i just tried some things and you can have multi-dimensional flexible arrays
try this
code: | var test:flexible array 1..0,1..0 on int
new test,2,3
test(2,3):=13
put test(2,3) | but i tried to see if i could get upper() to find the upper bounds of the 2nd dimension but i could only get the first bounds |
|
|
|
|
|
Cervantes
|
Posted: Tue Apr 26, 2005 8:49 pm Post subject: (No subject) |
|
|
Interesting. I thought you could only resize the first dimension of the array, not the second. It seems that you can resize the second dimension as well, if it starts as 1 .. 0.
Or... scratch that. It seems you can normally resize all dimensions of a flexible array except the last one. I say normally because you can't resize the last dimension of the flexible array if it started from something other than 1 .. 0. But if it did start as 1 .. 0, it seems we've got free reign!
Woo-hoo! |
|
|
|
|
|
c0bra54
|
Posted: Tue Apr 26, 2005 9:32 pm Post subject: (No subject) |
|
|
w00t free reign for multidimensional arrays, yipee lol
here to (insert name of person that got it to work)
+BITSSSSSS
lol[/code] |
|
|
|
|
|
Bacchus
|
Posted: Tue Apr 26, 2005 10:02 pm Post subject: (No subject) |
|
|
but heres a question for you Cervantes, you know how you can use upper(arrayname) to get the upper bounds of the array 1st array (makes it easier to add one), how could you use upper() to find the upper bounds of the say 2nd dimension of the array?
*edit: i also just tested wat you said about not being able to change the topmost dimension unless it was 1..0, that sadly is true but you are able to change it from whatever you want say 1..13 back to 1..0 and then change it once again to the number you choose say 1..14, once step more but it works |
|
|
|
|
|
TheEvilOne
|
Posted: Wed Apr 27, 2005 10:42 am Post subject: (No subject) |
|
|
Well, thats awesome. Except as far as I can see, you cant make another array in the first one... as in
code: |
var test:flexible array 1..0,1..0 on int
new test,2,3
test(2,3):=13
put test(2,3)
|
into
code: |
var test:flexible array 1..0,1..0 on int
new test,2,3
test(3,3):=13 %Changed
put test(2,3)
|
since I would want another in there. I can get more across so to speak, but not down.
EDIT:
Ok I see now, if I put:
code: |
new test,newnumberdown,newnumberacross
|
that works =) |
|
|
|
|
|
Cervantes
|
Posted: Wed Apr 27, 2005 4:12 pm Post subject: (No subject) |
|
|
Bacchus wrote: but heres a question for you Cervantes, you know how you can use upper(arrayname) to get the upper bounds of the array 1st array (makes it easier to add one), how could you use upper() to find the upper bounds of the say 2nd dimension of the array?
the upper and lower commands have optional parameters after the first parameter. That's where you enter the dimension of the array you want. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bacchus
|
Posted: Wed Apr 27, 2005 6:30 pm Post subject: (No subject) |
|
|
ah i get it, thxs so defualt if not entered is 1 |
|
|
|
|
|
|
|