Results 1 to 4 of 4

Thread: Collision Detection Code Error: SubScript Out OF Range?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22

    Collision Detection Code Error: SubScript Out OF Range?

    i am writing a side scroller and am writting a collision checker using loops, so i wouldnt have to go through and check against ALL the objects on the screen....

    ___________________________________________
    Public Sub Collision_Detection(Mainrect As RECT, fall As Boolean, NumberInArray As Integer, ComputerPlayer As Boolean)
    Dim TempRect As RECT

    'main rect is the rect which we are checking for collisons
    'if there is a collision, fall = true
    'NumberInArray is the number in the array of players
    'ComputerPlayer decides how to check through players

    If ComputerPlayer = False Then
    For i = 1 To (NumberInArray - 1)
    fall = IntersectRect(TempRect, Mainrect, destrectplayer(i))
    Next i

    For i = (NumberInArray + 1) To 14
    fall = IntersectRect(TempRect, Mainrect, destrectplayer(i))
    Next i

    For i = 1 To 7
    fall = IntersectRect(TempRect, Mainrect, destrectcomputer(i))
    Next i
    Else
    For i = 1 To (NumberInArray - 1)
    fall = IntersectRect(TempRect, Mainrect, destrectcomputer(i))
    Next i

    For i = (NumberInArray + 1) To 14
    fall = IntersectRect(TempRect, Mainrect, destrectcomputer(i))
    Next i

    For i = 1 To 7
    fall = IntersectRect(TempRect, Mainrect, destrectplayer(i))
    Next i
    End If

    End Sub
    _____________________________________

    and when ever i get to the code marked in red, it crashes with subscript out of range....what does this mean? any idea what i am doing wrong ?

    thanks for your help...
    Last edited by JSG; Sep 11th, 2001 at 05:33 AM.
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi
    Can we see the IntersectRect function cos that will be where the problem is. Is that function returning a boolean? Are u passing the expected parameters to the function?
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3
    Zaei
    Guest
    You are trying to index a value that is not in the array. Try starting your array at 1 again. Example:
    Code:
    4 items in array
    [0][1][2][3]
    items(4) = 2 'error, there is no index 4
    Z.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2001
    Posts
    22
    hey thanks alot!

    i spent the better part of my day trying to change 14 to 7
    Two Wrongs May Not Make A Right, But Three Rights Make A Left....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width