Delete an entity

Blitz3D Forums/Blitz3D Programming/Delete an entity

Mathieu A(Posted 2003) [#1]
Hi!
I've got a problem when I want to delete an entity.

Function DELETE_ENTITY()
If KeyHit(57) Then
For mesh.meshinfo=Each meshinfo
If picked=mesh\mesh
FreeEntity mesh\mesh

EndIf
Next
EndIf
End Function

The DELETE_ENTITY function works but after I call an other function to pick an entity and aplly an alpha on it.

Function PICK_ENTITY()

If MouseDown(1) And mouseInView() Then

picked = CameraPick (camera, mxp, myp)

If picked

CameraProject camera, EntityX (picked, 1), EntityY (picked, 1), EntityZ (picked, 1)
PositionEntity Gizmo, EntityX(picked), EntityY(picked), EntityZ(picked)
EntityParent picked, 0

EndIf
EndIf

For mesh.meshinfo = Each meshinfo
If mesh\mesh=picked
EntityAlpha mesh\mesh, 0.8
Else
EntityAlpha mesh\mesh,1
EndIf
Next
End Function

I've got an error message!!!

In fact, it's in the next lines that there is a problem.

For mesh.meshinfo = Each meshinfo
If mesh\mesh=picked
EntityAlpha mesh\mesh, 0.8
Else
EntityAlpha mesh\mesh,1
EndIf
Next

I think that the program want to apply an alpha on an entity deleted and I don't know how to do


Kev(Posted 2003) [#2]
Function DELETE_ENTITY()
If KeyHit(57) Then
For mesh.meshinfo=Each meshinfo
If picked=mesh\mesh
FreeEntity mesh\mesh
delete mesh
EndIf
Next
EndIf
End Function

your not deleting the type's instance 'delete mesh', or if you required to keep all types then you will need to set the mesh's pointer to zero then once you have freed it. do a check mesh mesh\mesh>0 to check you have a vaid pointer to your meshs.


Mathieu A(Posted 2003) [#3]
Oh thank you very much Kev, It woks fine! I never notice that function (delete) before!!!


dirkduck(Posted 2003) [#4]
Yep, FreeEntity just clears the actual entity's internal information. After you free it, you still have the type object, and your trying to apply EntityAlpha to an entity that was deleted. By using 'delete' the type object won't come up when you scroll through them all (for...each), so it won't try to set the EntityAlpha to an entity that no longer exists.