Computer Science Canada Help With Array Subscripts |
Author: | Slaivis [ Wed Jun 28, 2006 9:57 pm ] | ||
Post subject: | Help With Array Subscripts | ||
Now, I'm not really new to arrays, but this one's got me stumped. I'm writing a game, and this is supposed to be the background. The goal is to draw lines of a length of 100 pixels, that start at the centre of the screen, grow to their full length, then radiate outwards. The effect is supposed to give the impression that the player is flying through space at warp speeds. However, what happens is that I get an array subscript is out of range order. I've tried following what the program does, but I don't understand how it could possibly be out of range because all of my arrays have maximum values either defined by variables, or values that aren't reached by the program at the time of the error. I don't know... Perhaps if you run this, you will have either the experience to know what the problem is, or an eye keen enough to spot it. Here's the code:
If you've made it this far, I salute you. - Thanks |
Author: | Mazer [ Wed Jun 28, 2006 10:04 pm ] |
Post subject: | |
I haven't got Turing with me, but a couple of things you may want to consider in order for us to help you: 1) Tell us where you get the error (ie, line number), this makes it easier on people who (like myself) don't have Turing available 2) Indent! For the same reason as above and more. |
Author: | Slaivis [ Wed Jun 28, 2006 10:45 pm ] | ||
Post subject: | |||
Alright, I was mostly counting on people running the program in Turing and hitting F2 to find both of those things, but I'll paste the information into the forum. This code should be indented, and the error first occurs at the variable that I've bolded. I haven't included the line number because the lines tend to get shifted over in the post. This is really irritating. I can't bold anything with the 'code' option, and the 'quote' option removes all indentation. I also seem to be unable to edit my post here. To make the problem code the most visible, I've surrounded it by three blank lines and commented on it.
|
Author: | Mazer [ Thu Jun 29, 2006 7:56 am ] |
Post subject: | |
The problem isn't that n is out of the range of ldc, but that ldc(n) is out of the range of lx. Is ldc(n) ever greater than zero? |
Author: | Slaivis [ Thu Jun 29, 2006 12:09 pm ] |
Post subject: | |
Mazer wrote: The problem isn't that n is out of the range of ldc, but that ldc(n) is out of the range of lx. Is ldc(n) ever greater than zero?
ldc(n) is never less than zero. I think you've led me to the solution. The thing is that ldc(n) is set to zero to initialize it, but the subscripts for lx are set from a minium value of one. Thus, my subscript is actually below the range, which is what completely threw me off because I'd never encountered something like that. This means that I should initialize my value of ldc as 1. - Thanks, Mazer! |