Computer Science Canada Flexible Arrays |
Author: | Mr. T [ Wed Aug 23, 2006 10:54 pm ] |
Post subject: | Flexible Arrays |
Using a flexible array how would I eliminate an element that is NOT the last element in the array? |
Author: | [Gandalf] [ Wed Aug 23, 2006 10:58 pm ] |
Post subject: | |
Swap it with the last element in the array, and then remove the last element. |
Author: | Mr. T [ Wed Aug 23, 2006 11:04 pm ] |
Post subject: | Alex's Opinion |
Is this what you mean by swapping? thing (3):= thing (upper (thing)) If not, how do you swap? |
Author: | [Gandalf] [ Wed Aug 23, 2006 11:11 pm ] | ||
Post subject: | |||
That's one part of swapping... But the whole process normally looks more like this:
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. |
Author: | Mr. T [ 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? |
Author: | [Gandalf] [ 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? |
Author: | Mr. T [ Thu Aug 24, 2006 12:23 am ] |
Post subject: | Alex's Opinion |
"theft" ![]() |
Author: | [Gandalf] [ Thu Aug 24, 2006 12:31 am ] |
Post 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. |
Author: | Mr. T [ 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)
|
Author: | [Gandalf] [ 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(). |
Author: | Mr. T [ 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?
|
Author: | Cervantes [ Thu Aug 24, 2006 7:39 am ] |
Post subject: | |
Read! |
Author: | Clayton [ Thu Aug 24, 2006 9:55 am ] | ||
Post 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:
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 ![]() |
Author: | Mr. T [ 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) |
Author: | Mr. T [ 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. |
Author: | Cervantes [ Thu Aug 24, 2006 4:36 pm ] |
Post subject: | Re: Alex's Opinion |
Mr. T wrote: Can I PM someone my code so I can show what I mean.
No. I'm getting very tired of this. One of the great things about forums is that the information in them continues to exist long after the thread or even the forum is dead. But when you go around PM'ing people your code, the thread is incomplete. You shouldn't be worried about people stealing your code. If they do, it's quite easy to prove that it is your code, simply because you posted it in this thread first. Every post is timestamped. Besides, I doubt anyone would steal your code, regardless of whether they get 'caught' or not. |
Author: | Mr. T [ Thu Aug 24, 2006 4:40 pm ] |
Post subject: | Alex's Opinion |
Fine, take a look. ![]() |
Author: | Clayton [ Thu Aug 24, 2006 7:26 pm ] |
Post subject: | |
thats all well and good, but there really is not reason for that if statement (if that is how it is in your full code), if they follow each other, you can still keep your "continueMove" boolean, but just run the moving line in the same if (unless, if as i think you may be trying to say, continue move gets set to false somewhere else down the line) |
Author: | Cervantes [ Fri Aug 25, 2006 4:03 pm ] |
Post subject: | Re: Alex's Opinion |
Mr. T wrote: Fine, take a look.
![]() Have you understood nothing of what I said? Taking it off afterwards is the same as sending mass PM's. |