|
-
Sep 11th, 2001, 05:29 AM
#1
Thread Starter
Junior Member
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....
-
Sep 11th, 2001, 05:37 AM
#2
PowerPoster
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
-
Sep 11th, 2001, 06:45 AM
#3
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.
-
Sep 12th, 2001, 03:24 AM
#4
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|