
-----------------------------------
MysticVegeta
Mon Mar 07, 2005 6:47 pm

2D arrays
-----------------------------------
I know what 2D arrays are but i have a question on hwo to use them, for example if i have a 2D array, how do i get them to match each other for example :

1st -> 1st
1st -> 2nd
1st -> 3rd

2nd -> 1st
2nd -> 2nd
2nd -> 3rd

3rd -> 1st
3rd -> 2nd
3rd -> 3rd

Match each other, hard to understand?? =S

-----------------------------------
person
Mon Mar 07, 2005 6:49 pm


-----------------------------------
wat does -> mean?

-----------------------------------
Flikerator
Mon Mar 07, 2005 8:18 pm


-----------------------------------
wat does -> mean?

I think it means "=".

-----------------------------------
ssr
Mon Mar 07, 2005 8:59 pm


-----------------------------------
do u get the question though?
umm
do u wanna replace all the values in the array that has the index with the same values?
ummm :P

-----------------------------------
Flikerator
Mon Mar 07, 2005 9:28 pm


-----------------------------------

var nums : array 1 .. 3 of int

for i : 1 .. 3
     nums (i) := 1
end for


Now they all equal 1. Is that what you wanted? Not sure what is meant by 2D array (Never heard of them).

-----------------------------------
person
Mon Mar 07, 2005 9:30 pm


-----------------------------------
2D arrays r arrays wich r stored in an array...i know someone (probably Cervantes) wrote a tutorial on it...all i remember was wat 2D arrays r and that it was a good tutorial

-----------------------------------
Bacchus
Mon Mar 07, 2005 9:51 pm


-----------------------------------
ex)
var test:array 1..5,1..5 of int
for i:1..5
   for a:1..5
      test(i,a):=i*a
   end for
end for that right there is a 2d array. so each array of 1..5 has another array of 1..5, so test(1,1) would = 1 , test(3,5) would = 15. hm.. maybe like a graph may work to explain best
test(1,*)=  test(1,1)
            test(1,2)
            test(1,3)
            test(1,4)
            test(1,5)
            
test(2,*)=  test(2,1)
            test(2,2)
            test(2,3)
            test(2,4)
            test(3,5)
            
test(3,*)=  test(3,1)
            test(3,2)
            test(3,3)
            test(3,4)
            test(3,5)
            
test(4,*)=  test(4,1)
            test(4,2)
            test(4,3)
            test(4,4)
            test(4,5)
            
test(5,*)=  test(5,1)
            test(5,2)
            test(5,3)
            test(5,4)
            test(5,5) kinda like that lol

-----------------------------------
person
Tue Mar 08, 2005 3:32 pm


-----------------------------------
:D thats 2D arryas in a nutshell!!! 

btw: ur not limited to just 2 dimensions, u can go all the way to watever if u like but that would be confusing and....(i digress)......

-----------------------------------
Token
Tue Mar 08, 2005 3:50 pm


-----------------------------------
okay now i have a question, is it possible to have a string variable inside an integer variable, or vice versa? like for example a high score, i would want to store the persons username and then theyre score, i could put them both into a string array but then i wouldent be able to sort them unless i used the strint function, any ideas?

-----------------------------------
Bacchus
Tue Mar 08, 2005 4:58 pm


-----------------------------------
i sugest using records

var player:array 1..2 of
        record
            name:string
            score:int
        end record

-----------------------------------
Flikerator
Wed Mar 09, 2005 4:06 pm


-----------------------------------
Its easy to suggest records when you don't explain how to use them  :roll: 

Yah after I asked what 2D arrays where I read a tutorial on them...Thanks though ;)

Records are VERY useful with arrays/flexible arrays.

-----------------------------------
Bacchus
Wed Mar 09, 2005 4:38 pm


-----------------------------------
srry i think kinda wierd and in my own way so i dont think to explain things at first
var player:array 1..2 of %making an array of 1..2 of the following
        record %starts the record lol
            name:string %gives the variable player(x) a sub variable 
            score:int %adds another subvariable
        end record %end the record, could have more variable if wanted
as an example you would do:
player(1).name:="Bob"
player(1).score:=13

that way 'Bob' would have a score of '13' sotred under the same variable, you can make a type by using records (pretty sure in tutorial) and u can even use records in records if you wanted to. just an easy way to store sub variable uynder one name to keep track of them

-----------------------------------
MysticVegeta
Fri Mar 11, 2005 7:18 pm


-----------------------------------
ex)
var test:array 1..5,1..5 of int
for i:1..5
   for a:1..5
      test(i,a):=i*a
   end for
end for that right there is a 2d array. so each array of 1..5 has another array of 1..5, so test(1,1) would = 1 , test(3,5) would = 15. hm.. maybe like a graph may work to explain best
test(1,*)=  test(1,1)
            test(1,2)
            test(1,3)
            test(1,4)
            test(1,5)
            
test(2,*)=  test(2,1)
            test(2,2)
            test(2,3)
            test(2,4)
            test(3,5)
            
test(3,*)=  test(3,1)
            test(3,2)
            test(3,3)
            test(3,4)
            test(3,5)
            
test(4,*)=  test(4,1)
            test(4,2)
            test(4,3)
            test(4,4)
            test(4,5)
            
test(5,*)=  test(5,1)
            test(5,2)
            test(5,3)
            test(5,4)
            test(5,5) kinda like that lol

Yea its something like that but if the first array is 2, 4, 5, 6, 3 and the second array is 3, 2, 5, 6, 1

then
 if
2 matches 3 then do blah
2 matches 2 then do blah
2 matches 5 then do blah
2 matches 6 then do blah
2 matches 1 then do blah

4 matches 3 then do blah
4 matches 2 then do blah
4 matches 5 then do blah
4 matches 6 then do blah
4 matches 1 then do blah

5 matches 3 then do blah
5 matches 2 then do blah
5 matches 5 then do blah
5 matches 6 then do blah
5 matches 1 then do blah

=S

-----------------------------------
Bacchus
Fri Mar 11, 2005 7:28 pm


-----------------------------------
try nested for loops
for i:1..upper(array1)
    for a:1..upper(array2)
        if array1(i)=array2(a) then
            %do stuff
        end if
    end for
end for

-----------------------------------
MysticVegeta
Fri Mar 18, 2005 5:39 pm


-----------------------------------
cool thanks :)
