freeing children before parent

Blitz3D Forums/Blitz3D Programming/freeing children before parent

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.

Hi I need to access the children of an entity and free them before I free the entity itself so I can make sure no-one is chasing any of the children,

here is my function which calls itself:
Function set_childs_target_to_zero(ship)

For s.ship=Each ship
If s\turret_attached=ship
set_childs_target_to_zero(s\ship_handle)
Set_Target_To_Zero(s\ship_handle)
FreeEntity s\ship_handle
Delete s
EndIf
Next

For s.ship=Each ship
If s\parent=ship
set_childs_target_to_zero(s\ship_handle)
Set_Target_To_Zero(s\ship_handle)
FreeEntity s\ship_handle
Delete s
EndIf
Next

End Function


it works o.k. for entities that have turrets attached but not for other children that use the s\parent field.