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
Posted: Wed Aug 23, 2006 11:42 pm Post subject: 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]
Posted: Thu Aug 24, 2006 12:21 am Post subject: Re: Alex's Opinion
Mr. T wrote:
I don't want to post my entire code just yet
Why not?
Mr. T
Posted: Thu Aug 24, 2006 12:23 am Post subject: Alex's Opinion
"theft"
[Gandalf]
Posted: Thu Aug 24, 2006 12:31 am Post subject: (No subject)
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.
Sponsor Sponsor
Mr. T
Posted: Thu Aug 24, 2006 12:37 am Post subject: 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)
code:
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 reaches the bottom of the screen
if (((item (i).y - 1) * 10) + 5) + item (i).size <= 0 then
item (i).x := item (upper (item)).x
item (i).y := item (upper (item)).y
item (i).size := item (upper (item)).size
item (i).vy := item (upper (item)).vy
item (i).check := item (upper (item)).check
new item, upper (item) - 1
end if
end for
end moveItems
var picLargeItem : int := Pic.FileNew ("Large.GIF")
var picSmallItem : int := Pic.FileNew ("Small.GIF")
var randItem : flexible array 1 .. upper (item) of int
for i : 1 .. upper (item)
randint (randItem (i), 1, 2)
end for
proc drawItems
for i : 1 .. upper (item)
if randItem (i) = 1 then
%Draw.FillOval (((round (item (i).x) - 1) * 20) + 10, (((round (item (i).y) - 1) * 10) + 5), round (item (i).size), round (item (i).size), black)
Pic.Draw (picLargeItem, ((round (item (i).x) - 1) * 20) + 6, ((round (item (i).y) - 1) * 10) + 1, picMerge)
elsif randItem (i) = 2 then
Pic.Draw (picSmallItem, ((round (item (i).x) - 1) * 20) + 6, ((round (item (i).y) - 1) * 10) + 1, picMerge)
end if
end for
end drawItems
[Gandalf]
Posted: Thu Aug 24, 2006 12:57 am Post subject: Re: Alex's Opinion
Mr. T wrote:
If I only post the relevant code, you won't be able to run the program for visual aid.
Yes, but it also means we won't have to sift through hundreds of lines of who knows what kind of code. If you narrow down a problem enough, it'll be a lot easier for us (or you) to find it. Though, like I said, having the complete code is also useful in some situations. You should also post what you have done to try to fix the problem, and even what you think is causing it. We shouldn't be doing all the work for you.
As for your error: In your code you are iterating through each of the items; from 1 to the amount of items at the time of the first iteration of the for loop. The problem is that you are changing the upper bound of the items inside the for loop, so the original amount of items no longer applies. Let's say you delete one item in that loop, the amount of items in now one less than it originally was, but Turing still expects the original amount of items.
Problems like this are fixed by compartmentalizing your code further, into, say checkBoundaries() and deleteItems().
Mr. T
Posted: Thu Aug 24, 2006 1:07 am Post subject: Alex's Opinion
I thought that maybe an exit statement right after the array update, would solve the problem. I know longer get the out of range error, but now, it seems that the entire array has shifted, and a new item is falling in the place of the item just removed from the array. Any other suggestions how can update the array?
code:
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
Posted: Thu Aug 24, 2006 9:55 am Post subject: (No subject)
damn Cervantes i was going to hotlink that, but apparently you get up earlier than me
now on topic:
theres one part in your code here that looks a bit weird:
Turing:
if item (i).check =truethen%%not collided
continueMove (i):=true endif
if continueMove (i)=truethen
item (i).y += item (i).vy %%move it down endif
why not just move the item (i).y += item (i).vy into the first if? all your doing is making continue move true in the first one, the next thing you do is if continueMove is true is move, so you can just move that line into the first if, and be done with the second one
Mr. T
Posted: Thu Aug 24, 2006 3:29 pm Post subject: Alex's Opinion
SuperFreak82, I know its hard to see the reason why I coded it like that. But in the game as a whole, it is neccessary. (ie. once a ball starts falling, it won't stop, even if something else is in the way)
Mr. T
Posted: Thu Aug 24, 2006 3:58 pm Post subject: Alex's Opinion
Cervantes, I used that tutorial, and it helped eliminate the error. However, there's still a problem. It seems that another item simply takes the place of the deleted item. By this I mean that the new item falls down as if it were the original item. Can I PM someone my code so I can show what I mean.