Delete Objetc?

Blitz3D Forums/Blitz3D Programming/Delete Objetc?

Yue(Posted 2016) [#1]

; ===================================================
; Proyecto 		: ISON.                     ;
; Programador 	: Yue Rexie. 			    ;
; Sitio Web		: http://www.iris3dgames.tk ;
; Nombre Fichero: TRobot.cs			    ;
; ===================================================
; Notas			: Tipo Robot - Objeto.	    ;
;						    ;
; ===================================================

Type TRobot
	
	Field malla.TMalla
	Field padre%
	
End Type 


Function Init_OTRobot.TRobot( padre% = False )
	
	
	Local oRobot.TRobot = New TRobot
	
	oRobot\padre%       = padre%
	oRobot\malla.TMalla = Init_OMalla.TMalla ( "Robot.b3d", padre%, False ) <<<<<<< Delete objetc finish Function ?
	
	
	Return ( oRobot.TRobot )
	
	
End Function 


Function DeInit_ORobot%()

Local oRobot.TRobot = Null
	
	For oRobot.TRobot = Each TRobot
		
		If ( oRobot.TRobot <> Null ) Then 
			
			Delete ( oRobot.TRobot )
			
		End If 
		
		
	Next 
	
End Function





Last object within a capo other one is removed , manually remove or touch ?


Floyd(Posted 2016) [#2]
Not sure what you are asking, but here is an example of removing one object and then removing all objects.
Graphics 600, 400, 0, 2
SetBuffer FrontBuffer()

Type thing
	Field n
End Type

For k = 1 To 3
	s.thing = New thing
	s\n = k
Next

Print
Print "Show entire list, delete item 2."
Print

For s.thing = Each thing
	Print s\n
	If s\n = 2 Then Delete s
Next

Print
Print "Show list again, then delete all."
Print

For s.thing = Each thing
	Print s\n
Next

Delete Each thing

count = 0
For s.thing = Each thing
	count = count + 1
Next

Print
Print "Number of items in list: " + count

WaitKey



Rick Nasher(Posted 2016) [#3]
If I understand correctly: you want to delete all objects in a type?

Then I think (not sure) to do the right way, free entity first(if any exists), then delete the object.
Function objdelete(o.obj) ; Delete object.
	If o\obj<>Null Then emitterdelete(o\remitter)
	    If o\entity<>0 Then FreeEntity o\entity
	Delete o
End Function


Function objdeleteall() ;Delete all objects.
	For o.obj=Each obj
		objdelete(o)
	Next
End Function


[edit: Aaargh.. Floyd beat me to it ;-)


Yue(Posted 2016) [#4]
Ok, Thanks You.
Type TMalla
	
	Field anim%
	Field malla%
	Field padre%
	
End Type


Function Init_OMalla.TMalla( nombreMalla$, padre% = 0, anim% = False )

	Local oMalla.TMalla  = New TMalla
	
	oMalla.TMalla\anim%  = anim%
	oMalla.TMalla\padre% = padre%
	
	oMalla.TMalla\malla% = TCargarMalla%( nombreMalla$, oMalla\padre%, oMalla\anim% )
	
	
	Return oMalla.TMalla
	
End Function

Function TCargarMalla%( nombreMalla$, padre%=False, anim%=False)
	
	
	InitZip%("Data/","Modelos.00")
	
	Local malla%
	
	Select anim%
			
		Case True
			
			malla% =xLoadAnimMesh(pak( nombreMalla$), padre% )
			
		Case False
	 		
	        malla% =xLoadMesh(pak( nombreMalla$), padre% )		
			
	End Select 
	
	PakClean%()
	
	Return malla%
	
	
End Function 


Function DeInit_OMalla%()
	
	
	Local oMalla.TMalla = Null 
	
	
	For  oMalla.TMalla = Each TMalla
		
		
		If ( oMalla\padre% ) Then 
			
			
			xEntityParent ( oMalla\malla%, 0 )
			
		End If 
		
		If ( oMalla\malla% ) Then 
			
			xFreeEntity( oMalla\malla% )
			
		End If 
			
		
		If ( oMalla.TMalla <> Null ) Then 
			
			Delete ( oMalla.TMalla )
			
		End If 
		
		
		
	Next 
	
	
	
End Function 


Local jugador.TRobot = Null

Type TRobot
	
	Field malla.TMalla
	Field padre%
	
End Type 


Function Init_ORobot.TRobot( padre% = False )
	
	
	Local oRobot.TRobot = New TRobot
	
	oRobot\padre%       = padre%
	oRobot\malla.TMalla = Init_OMalla.TMalla ( "Robot.b3d", padre%, False )
	
	xEntityAddConcaveShape(oRobot\malla\malla%, 10)
	
	xEntityReleaseForces(oRobot\malla\malla%)
	
	xRotateEntity(oRobot\malla\malla%, -35.0, 0.0, 0.0)
	xEntityWakeUp(oRobot\malla\malla%)
	
	Return ( oRobot.TRobot )
	
	
End Function 


Function DeInit_ORobot%()
	
	Local oRobot.TRobot = Null
	
	
	If ( oRobot\malla.TMalla <> Null ) Then 
		
		
		DeInit_OMalla%()
		
	End If 
	
	
	
	For oRobot.TRobot = Each TRobot
		
		If ( oRobot.TRobot <> Null ) Then 
			
			Delete ( oRobot.TRobot )
			
		End If 
		
		
	Next 
	
	
End Function