
-----------------------------------
[Gandalf]
Mon Jun 20, 2005 4:21 pm

2D Arrays, or Something?
-----------------------------------
I'm just a bit confusled right now, having an exam and the sort tomorrow.  
Let's say I had this:
var bullet : flexible array 1 .. 0 of
    record
        x, y
    end record
How would I add a say, bullet(2) so that I don't have to copy the whole thing and rename the new bullet to bullet2.  So pretty much what I'm asking is, how would I shorten something like this:
var bullet : flexible array 1 .. 0 of
    record
        x, y : real
    end record

var bullet2 : flexible array 1 .. 0 of
    record
        x, y : real
    end record
Thanks.

-----------------------------------
Bacchus
Mon Jun 20, 2005 4:39 pm


-----------------------------------
Ok, now I'm a bit confusled about what you mean. Do you mean like a shorter way of making another array with the same record?
type positions :
    record
        x, y : real
    end record
var bullet : flexible array 1 .. 0 of positions
var bullet2 : flexible array 1 .. 0 of positions Or do you mean adding another bullet to your array?
var bullet : flexible array 1 .. 0 of
    record
        x, y : real
    end record
new bullet, 2 Or do you mean like adding another dimension to the flexible array? Please explain a bit more.

-----------------------------------
lyam_kaskade
Mon Jun 20, 2005 4:40 pm


-----------------------------------

type foo :
    record
        x, y : int
    end record

var bullet : flexible array 1 .. 0 of foo
var bullet2 : flexible array 1 .. 0 of foo
[/code]

-----------------------------------
Cervantes
Mon Jun 20, 2005 4:41 pm


-----------------------------------
Well, you can make it into a type and then create different variables:

type obj :
     record
         x, y, : real
     end record
var bullet : flexible array 1 .. 0 of obj
var bullet2 : flexible array 1 .. 0 of obj

But if you've got a flexible array of bullets, why are you making bullet and bullet2?  In any case, if you must do that, you could try a 2D array.

type obj :
    record
        x, y : real
    end record
var bullet : flexible array 1 .. 0, 1 .. 0 of obj

EDIT: 2 posts got there before me.  Yee-gawds!

-----------------------------------
[Gandalf]
Mon Jun 20, 2005 5:05 pm


-----------------------------------
Ya, thanks - I was forgetting about types  :doh: 

But if you've got a flexible array of bullets, why are you making bullet and bullet2?
Well, they're not two different bullets, they're two kinds of bullets going in different directions.

-----------------------------------
MysticVegeta
Mon Jun 20, 2005 6:35 pm


-----------------------------------
doh! there can be a flexible array with mutiple dimension, jeez and all this time i have been sleeping  :shocked:

-----------------------------------
Cervantes
Mon Jun 20, 2005 6:53 pm


-----------------------------------
I was pressured into adding that to the tutorial.  Check it out :)

-----------------------------------
Bacchus
Mon Jun 20, 2005 9:38 pm


-----------------------------------
Even though in your Tutorial Cervantes, you list some basic rules... Like In a 2D array, if you leave one upper bounds alone, you can do whatever you want to the other bounds. That doesn't work :( Try it out:
var foo:flexible array 1..3,1..2 of int
new foo,3,3 There is a bit of a way around this, takes up a bit of space thought. Just create a new array (doesn't have to be flexible) and store the orginal array in that then change the dimension to 0 and back to what you want before restoring the original array's values. lol

-----------------------------------
Cervantes
Tue Jun 21, 2005 9:56 am


-----------------------------------
Ooh, thanks for that, Bacchus.  It's updated. :)

-----------------------------------
MysticVegeta
Tue Jun 21, 2005 11:05 am


-----------------------------------
Just create a new array (doesn't have to be flexible) and store the orginal array in that then change the dimension to 0 and back to what you want before restoring the original array's values. lol

i see i see, pretty nifty.I think the reason they cant make it 3, 3 is because turing doesnt know the flexiblility of the elements of each of the dimensions of the flexible array.

-----------------------------------
Cervantes
Tue Jun 21, 2005 1:07 pm


-----------------------------------
Bah!  This is not so pretty!

var list : flexible array 1 .. 3, 1 .. 2 of int
for i : 1 .. upper (list, 1)
    for j : 1 .. upper (list, 2)
        list (i, j) := i * j
    end for
end for

var tempArr : array 1 .. upper (list, 1), 1 .. 4 of int
for i : 1 .. upper (tempArr, 1)
    for j : 1 .. upper (tempArr, 2)
        if i 