Type Problem

Blitz3D Forums/Blitz3D Beginners Area/Type Problem

Q(Posted 2006) [#1]
Does anyone see a problem with this code:

		If B\MOUSE_OVER=True
			If MOUSE_X >= B\BX And MOUSE_X <= B\BX+B\WIDTH
				If MOUSE_Y >= B\BY And MOUSE_Y <= B\BY+B\HEIGHT
					If KeyHit(N)=True
						B\SNAP=True
					EndIf
					If KeyHit(DELETE_KEY)=True
						Delete B
					EndIf
					If B\SNAP=False
						Rect B\BX,B\BY,B\WIDTH,B\HEIGHT,1
					Else
						Rect B\BGX,B\BGY,B\WIDTH,B\HEIGHT,1
					EndIf
				EndIf
			EndIf
		EndIf


Whenever I try to delete the type B I get a 'MAV" error..


Matty(Posted 2006) [#2]
The following line "IF B\Snap=false" is causing you the error. You should either delete the type instance 'B' last, or set a flag to delete the instance and do so at the end of your loop

When it gets to the line " if B\snap=false " b no longer exists.


Q(Posted 2006) [#3]
Makes sense, thanks!


Ross C(Posted 2006) [#4]
If your thinking of deleting types with lots of if's, then:


If b\x = 5 then
   delete b
ElseIf b\y = 6 then
   delete b
end if



instead of


If b\x = 5 then
   delete b
End If
If b\y = 6 then
   delete b
end if



The first one will not produce the error, the second one however will.


Sir Gak(Posted 2006) [#5]
How about this?
If b\x = 5 or b\y = 6
   delete b
end if



Subirenihil(Posted 2006) [#6]
Even shorter is:

If b\x = 5 Or b\y = 6 Then Delete b

Pentium4 3.2Ghz, 1GB RAM, nVidia GeForce 6800 256MB, SB Audigy ZS


Sir Gak(Posted 2006) [#7]
@subirenihil
Show off! LOL