array boundary problems

I am currently makeing a program which involves moving an object around the screen. The object is stored in an array but when you move the object of screen it crashes and has the "subscript out of bounds" error. Can someone please tell me how to stop this from happening or how to make it "bounce" of the edge of the screen? Thanks


Array boundary problems

wikaman1 ... Your object array problem is familiar, and is - I think - easily fixable. You need to create your object array as a "circular buffer" array. As you increase the "row index" or "column index" as you "move" your object around the screen, you must use modulo arithmetic in increasing your row and or column index number(s).

Accordingly, your array index number(s) never exceed the row or column array upper bound numbers; they reset to zero before exceeding the "ubound" numbers, and you overwrite "old" array data with "new" array data, thereby avoiding your program "crash". Your "move" index constantly increases by 1, but your array indexes never exceed the array upper bounds.

I published a TB program, in the "old" TB website, that showed how to compute Fibonacci numbers of arbitrary order; it contained a circular buffer array. Regards ... Tom M

array boundary problems

You probably keep track of the object's position by a couple variables for the X and Y-axes. In order to keep the object on the screen, you have to test both X and Y BEFORE you move the object. If either is out of your pre-defined bounds, then skip the move. If you want to bounce the object, you have to change the sign of your movement amount (usually referred to as delta)