Big Shooting Problem
Blitz3D Forums/Blitz3D Programming/Big Shooting Problem
| ||
when i only have one enemy on the screen i can shoot it just fine. but when i have multiple enemies on the screen and i shoot one it gives me a error. here is the code. help? For collide.enemy = Each enemy For hit.ball = Each ball If MeshesIntersect(hit\entity, collide\entity1) Then FreeEntity collide\entity1 Delete collide FreeEntity hit\entity Delete hit score=score+100 End If Next Next |
| ||
'delete collide.enemy' and 'delete hit.ball' should be in place of 'delete collide' and 'delete hit': as your deleting the variable with which you access the type,as appose to that particular type object, all types are then in an unreachable state of memory. |
| ||
For Collide.Enemy = each Enemy colhit=0 For Hit.ball=each Ball if meshesintersect(hit\entity,collide\entity1) then colhit=1 freeentity hit\entity delete hit score=score+100 endif next if colhit=1 then freeentity collide\entity1:delete collide next The reason for putting the "delete collide" outside of the "for hit.ball=each ball" loop is that while iterating through that loop you are still referencing the collide type instance and if you were to delete it within the "for hit.ball = each ball" loop, when you refer to "collide\entity1" the collide instance no longer exists thus generating an error. Oh and you might want to use a different method than meshintersect as it is quite a slow command, there are many faster ways of detecting collisions. |