
-----------------------------------
Mr. T
Wed Aug 23, 2006 10:54 pm

Flexible Arrays
-----------------------------------
Using a flexible array how would I eliminate an element that is NOT the last element in the array?

-----------------------------------
[Gandalf]
Wed Aug 23, 2006 10:58 pm


-----------------------------------
Swap it with the last element in the array, and then remove the last element.

-----------------------------------
Mr. T
Wed Aug 23, 2006 11:04 pm

Alex's Opinion
-----------------------------------
Is this what you mean by swapping?
thing (3):= thing (upper (thing))
If not, how do you swap?

-----------------------------------
[Gandalf]
Wed Aug 23, 2006 11:11 pm


-----------------------------------
That's one part of swapping...  But the whole process normally looks more like this:
tempThing = thingB
thingB = thingA
thingA = tempThing

For your purposes, though, what you have is enough, since you don't really care about what the last element is when you delete it.

-----------------------------------
Mr. T
Wed Aug 23, 2006 11:42 pm

Alex's Opinion
-----------------------------------
I did what you suggested, but I'm still getting an array subscript out of range error.  I don't want to post my entire code just yet, so can I PM it to you?

-----------------------------------
[Gandalf]
Thu Aug 24, 2006 12:21 am

Re: Alex's Opinion
-----------------------------------
I don't want to post my entire code just yet
Why not?

-----------------------------------
Mr. T
Thu Aug 24, 2006 12:23 am

Alex's Opinion
-----------------------------------
"theft"  :roll:

-----------------------------------
[Gandalf]
Thu Aug 24, 2006 12:31 am


-----------------------------------
Fine, if you really believe that is a problem...

Other people manage, even without posting their entire code.  It's probably better that way too, makes it easier to help you, though occassionally it comes in handy to see the whole thing.  Post only the code relevant to your problem.  That way, you don't have to be worried about someone stealing your program, and we can still try and help you find the problem.

Private messages are simply not the place for help discussion, especially when you spam the same message to multiple people.  That's what the help sections are for.

-----------------------------------
Mr. T
Thu Aug 24, 2006 12:37 am

Alex's Opinion
-----------------------------------
If I only post the relevant code, you won't be able to run the program for visual aid.  Anyways, heres the section: 
(the error "subscript array is out of range" occurs at this line -->         item (i).check := allowableBoundries (i)
type items :
    record
        x, y : real
        size : real
        vy : real %%how fast it will fall
        check : boolean %%%%%oooooooooo!!!!!
        %%can have more, like color, etc:
    end record

var item : flexible array 1 .. 15 of items
var itemX, itemY : array 1 .. 15 * 30 of int
var positionInItemArray : int := 1
var randomItemLocation : int := 0
proc itemInitialization
    for a : 1 .. 15
        for b : 1 .. 30
            if grid (a, b) not= 0 then
                itemX (positionInItemArray) := a
                itemY (positionInItemArray) := b
                positionInItemArray += 1
            end if
        end for
    end for

    for i : 1 .. upper (item)
        item (i).size := 2
        randomItemLocation := Rand.Int (1, positionInItemArray - 1)
        item (i).x := itemX (randomItemLocation)
        item (i).y := itemY (randomItemLocation)
        item (i).vy := -0.25
    end for
end itemInitialization


fcn allowableBoundries (num : int) : boolean
    if grid (round (item (num).x), round (item (num).y)) not= white then
        result false
    else
        result true
    end if
end allowableBoundries

%purpose of this array = once item starts falling, it WON't stop (even if it hits another brick)
var continueMove : flexible array 1 .. upper (item) of boolean
for i : 1 .. upper (item)
    continueMove (i) := false
end for

var move : int := 0
proc moveItems
    for i : 1 .. upper (item)

        item (i).check := allowableBoundries (i)

        if item (i).check = true then             %%not collided
            continueMove (i) := true
        end if

        if continueMove (i) = true then
            item (i).y += item (i).vy             %%move it down
        end if

        %item hits the paddle
        if Math.DistancePointLine ((((item (i).x - 1) * 20) + 10) + item (i).size, (((item (i).y - 1) * 10) + 5) + item (i).size, (maxx div 2 - 20) + move, 8, (maxx
                div 2 + 27) + move, 8) 