Why is attached code so slow?

BlitzPlus Forums/BlitzPlus Programming/Why is attached code so slow?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

the code is slow because you are making 30 instances of the type AlienData every loop through this function.

the line "If score Mod 10 = 0 Then InitAlien()" is 0 all the time, so although the aliens get killed, instantaneously new ones appear. Comment out the line and try it.


Function CheckCollision()
	For Bullet.BulletData = Each BulletData
		For Alien.AlienData = Each AlienData
			If ImagesOverlap(bullets,Bullet\xpos,Bullet\ypos,Aliens,Alien\xpos,Alien\ypos) Then
				PlaySound Alienhit
				score = score + 1000
				Delete Alien
			EndIf
		Next
	Next
	If score Mod 10 = 0 Then InitAlien()
End Function


and Mark, look for some nice code examples and check out the formatting, makes it so much easier to decipher if it is nicely formatted. And also, it is maybe better too, if you have a variable "Aliens" not to call it "aliens", and having a variable "Aliens" and another one "Alien" is OK, but kinda confusing too :)