Type Deletion Problem

Blitz3D Forums/Blitz3D Beginners Area/Type Deletion Problem

Crazy4Code(Posted 2005) [#1]
Function TestShotAst()
For a.ast = Each ast
For s.shots = Each shots

If ImagesCollide(a\img,a\x,a\y,0,s\img,s\x,s\y,0)
as.ast = New ast
as\x = a\x
as\y = a\y
as\rot = 0
as\size = a\size + 1
as\img = aimg0(a\rot)
as\vx = Rnd(-2,2)
as\vy = Rnd(-2,2)
a\size = a\size + 1
Delete s
End If 
Next
Next
End Function 


I know I've had this exact same problem before, but I can't remember how I fixed it. Anyways, this is the function in my little Asteroids game that checks to see if the players shot has hit the asteroid. It makes a new asteroid and makes the old one smaller. The problem is, if there is more than one shot on the screen, It gives me an error "Image does not exist" and it highlits the "If ImagesCollide(a\img,a\x,a\y,0,s\img,s\x,s\y,0)" line. I know I've fixed this problem before, and I'm sure it's very simple, but I can't see the problem right now, can anyone else?


Ross C(Posted 2005) [#2]
Delete s


change to

Delete s.shots



Crazy4Code(Posted 2005) [#3]
Nope, still doesn't work.


Ross C(Posted 2005) [#4]
Come to think of it, shouldn't you be checking each asteroid against each shot? You seem to be checking the other way around. Check your debuglog too. What does the type collections contain?


Crazy4Code(Posted 2005) [#5]
I've tried flipping many things around. If I flip the fors around, it says Object does not exist instead of image, and if I flip the ImagesCollide part around, it does the same thing. I think I'm looking at the right thing here for the debug log. Under TestShotAst() it says a.ast and all it's variables, s.shots and all it's variables, and a.ast and all it's variables.


Ross C(Posted 2005) [#6]
could you give me some working code?


Crazy4Code(Posted 2005) [#7]
You just want the whole thing? I can put the graphics on my webspace.


Ross C(Posted 2005) [#8]
Yes please :o)


Crazy4Code(Posted 2005) [#9]
It's Here: http://www.antibox.net/grant/Asteroids(Working Title-In Progress).zip


Crazy4Code(Posted 2005) [#10]
Oh sorry, and the controls are left and right and up and spacebar.


Curtastic(Posted 2005) [#11]
aimg0(0) is empty
you only set aimg() from 1 to 30
So as\rot needs to equal a number from 1 to 30. It can't be 0

Don't even try to do this:
as\img = "aimg" + a\size + "(a\rot)"
after that as\img equals 0

You just need to check when your images equal 0 for better debugging.


Crazy4Code(Posted 2005) [#12]
aimg0(0) does equal something. It equals astim.
Dim aimg0(30)
aimg0(0) = astim
For i = 1 To 30
aimg0(i) = CopyImage(astim)
RotateImage aimg0(i),12 * i
Next


Curtastic(Posted 2005) [#13]
ok the game works nicely for me just change the "as\img =" line


Crazy4Code(Posted 2005) [#14]
Ohhhhh... Your right. I see what was happening. It works now. Thanks!

Oh, and thanks for the fireworks code Ross C. I'm going to use it for the new highscore screen. It doesn't have much to do with space, but still... I'll give you credit, don't worry :)


Curtastic(Posted 2005) [#15]
Your welcome. You could also use a 2D array like this:
Dim aimg(3,30)
...
as\img = aimg(as\size,as\rot)
thats probably what I would do