
-----------------------------------
JayLo
Tue Apr 15, 2003 5:02 pm

Initializing a two/three dimensional array.
-----------------------------------
how do you initialize values for a two dimensional array?
I know that arrays would be:
var x : array 1 .. 3 of int := init (3,5,7)
but what about 2d arrays?

-----------------------------------
Blade
Tue Apr 15, 2003 5:15 pm


-----------------------------------
heres the example from help
Example   
        var mensNames : array 1 .. 3 of string :=
            init ( "Tom", "Dick", "Harry" )
        put mensNames ( 2 )             % This outputs Dick
        var names : array 1 .. 2, 1 .. 3 of string :=
            init ( "Tom", "Dick", "Harry",
                 "Alice", "Barbara", "Cathy")
        put names ( 2, 1 )  % This outputs Alice
 

it should explain it for you

-----------------------------------
Tony
Tue Apr 15, 2003 5:19 pm


-----------------------------------
once again, read the tutorial on the arrays. It covers EVERYTHING you need to know, including explanation of multidimentional arrays.

-----------------------------------
Blade
Tue Apr 15, 2003 5:34 pm


-----------------------------------
i read it and it didnt tell me how to initilize 2d arrays...

-----------------------------------
Tony
Tue Apr 15, 2003 5:53 pm


-----------------------------------
read the tutorial again  :evil: 

Some array tricks - 2D arrays 
Here's something that I used to scare people with right before grade10 compsci exam... "you need to know 2D arrays". People were freaking out... I donno why  

Anyway, the point is that each of our little "boxes" in an array can contain a row of boxes of its own. So for each box in a row, we get another row, forming columns. This way we just created a grid (also called matrix). 

it's decleared as 
Code: 

var grid:array 1..10, 1..5 of int 
 


10 rows, 5 columns. Though that depends how you look at it and how you set up your forloops. I had a huge argument with my teacher of what value gous first - row or column. I dont remember what she said, but in my opinion it doesnt matter - as long as you know  


-----------------------------------
Catalyst
Tue Apr 15, 2003 6:07 pm


-----------------------------------
i think he means using the init command...

-----------------------------------
Tony
Tue Apr 15, 2003 6:53 pm


-----------------------------------
ah crap.

Blade is right then.

though why initialize arrays? just get info from a file :wink:

-----------------------------------
Blade
Tue Apr 15, 2003 9:21 pm


-----------------------------------
YAY BLADE IS RIGHT!! go blade go, oh yeah uh huh! :D hehe i wouldnt have argued with you if i didnt know i was right tony  :wink:

-----------------------------------
JayLo
Wed May 07, 2003 6:16 pm


-----------------------------------
about initializing from a text file...
how? :oops:

-----------------------------------
Tony
Wed May 07, 2003 6:43 pm


-----------------------------------
:= init(variable1, variable2, ... , variableN)

or just read from the file and save values right in the array

-----------------------------------
Homer_simpson
Wed May 07, 2003 7:11 pm


-----------------------------------
my new tetris project uses 2d arrays that might help u if u take a look at it....
