deleting types

Blitz3D Forums/Blitz3D Beginners Area/deleting types

Aussie(Posted 2010) [#1]
I have created a function for creating fake lights with lightmesh.
I was wandering is there a way to delete a type the same or simmilar to the way you would clear an entity.
Eg
cube = createcube()
freeentity cube

light1 = create_dy_fklight(lightsphere,0,100,255,5)

is there a way to delete the type by calling Light1 in some way.
Hope this makes sence. : )


Warner(Posted 2010) [#2]
You can use the "Delete" command:
light.TLight = new TLight
delete light

To find out if 'light' was deleted, check if (light = null).


Aussie(Posted 2010) [#3]
Is there then a way to make light1, light2 ,light3......... the name of the type from a function so i could just call Delete Light1, or would i be better off just creating a new type for every light without a function & then Delete it when needed.

Here is the test i have been playing with anyway. I hope to be able to use it for lighting from explosions, bullets & the like in an asteroids clone i am working on.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;Fakelight test
;
;Author: Robert Hogg
;Date  : 24\4\2010
;
;Fklightentity(entity,fx(2 or 3),ambient_R,ambient_G,ambient_B,) sets entitys ambient light color
;																 & lighting effects. Fx 2 Dxlights & 
;																 fake. Fx 3 fake lights only.
;
;create_st_fklight(X,Y,Z,R,G,B,Range) creates a static fakelight.
;
;create_dy_fklight(Parent,R,G,B,Range) creates a dynamic light that needs to be parented to an
;									   entity. Move the parent entity to affect fakelights position.
;									   Will eventualy be able to change the r,g,b values & the range.
;
;Update_fklightentity() must be called at the end of a loop to reset entitys light effects.
;
;update_st_fklights() must be called to update all static lights
;
;update_dy_fklights() must be called to update dynamic lights
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AppTitle "Fakelight Test"

Graphics3D 640,480,16,2
 
Global lighton
	
cube=CreateCube()
	PositionEntity cube,0,0,0


cone=CreateCone(20)
	PositionEntity cone,-5,0,0
	
	
cyl=CreateCylinder(20)
	PositionEntity cyl,5,0,0
	
	
camera=CreateCamera()
	PositionEntity camera,0,5,-15

piv=CreatePivot()
	PositionEntity piv,EntityX(cube),EntityY(cube),EntityZ(cube)
	sphere = CreateSphere(20,piv)
	PositionEntity sphere,0,0,10
	
light = CreateLight()
	RotateEntity light,90,0,0
	

fklightentity(cube,2,100,100,100)

fklightentity(cone,3,100,100,100)

fklightentity(cyl,3,100,100,100)

fklightentity(sphere,3,100,100,100)

;create_st_fklight(0,-15,0,0,255,0,5)
;create_st_fklight(-15,0,0,0,0,255,5)
;create_st_fklight(15,0,0,255,0,0,5)
;create_st_fklight(0,0,-15,200,255,0,5)
create_st_fklight(0,2,10,255,0,255,2)
create_st_fklight(-10,2,0,0,255,255,2)
create_st_fklight(0,2,-10,255,255,255,2)
create_st_fklight(10,2,0,255,255,0,2)


piv1=CreatePivot()
	PositionEntity piv,EntityX(cube),EntityY(cube),EntityZ(cube)
	
lightsphere = CreateSphere(20,piv1)
	EntityColor lightsphere,0,100,255
	PositionEntity lightsphere,0,0,-11
	EntityFX lightsphere,1
	;fklightentity(lightsphere,3,100,100,100)
	
	
create_dy_fklight(light1,lightsphere,0,100,255,5)


lighton = True
If lighton Then ShowEntity light
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While Not KeyDown(1)

If KeyHit (57)
	lighton= Not lighton
	If lighton Then ShowEntity light Else HideEntity light ; turns light on & off
EndIf

PointEntity camera,cube
	 
TurnEntity cube,1,1.5,2
TurnEntity cone,.5,.1,0
TurnEntity cyl,-.5,-.1,0

TurnEntity piv,0,1,0
TurnEntity piv1,.5,0,0


Update_fklightentity()
update_st_fklights()
update_dy_fklights()

UpdateWorld

RenderWorld

Text 0,0,"The cube is lit with both fake & DXlights."
Text 0,12,"Press space to turn on & off DXLight."

Flip 
Wend 
End



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Type fklightentity
	Field entity
	Field fx%
	Field ambientr%
	Field ambientg%
	Field ambientb%
End Type


Function fklightentity(entity,fx%,ambientr,ambientg,ambientb)
	Light.fklightentity = New fklightentity
		Light\entity=entity
		LightMesh Light\entity,-255,-255,-255
		EntityFX Light\entity,fx%
		Light\ambientr=ambientr
		Light\ambientg=ambientg
		Light\ambientb=ambientb
	LightMesh Light\entity,Light\ambientr,Light\ambientg,Light\ambientb
End Function

Function Update_fklightentity()
	For Light.fklightentity = Each fklightentity
		LightMesh Light\entity,-255,-255,-255
		LightMesh Light\entity,Light\ambientr,Light\ambientg,Light\ambientb
	Next
End Function


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Type fklight
	Field light_piv
	Field entity
	Field light
	Field red#
	Field green#
	Field blue#
	Field range#
	Field x#
	Field y#
	Field z#
End Type
	
Function create_st_fklight(x#,y#,z#,r#,g#,b#,range#)
	light_fake.fklight = New fklight
		light_fake\light_piv = CreatePivot()
		

		light_fake\x=x#
		light_fake\y=y#
		light_fake\z=z#
		
		light_fake\red#=r#
		light_fake\green#=g#
		light_fake\blue#=b#
		
		light_fake\range#=range#
End Function


Function update_st_fklights()
		
	For light_fake.fklight = Each fklight
		PositionEntity light_fake\light_piv,light_fake\x#,light_fake\y#,light_fake\z#

		For Light.fklightentity = Each fklightentity
			If (Light.fklightentity <> Null) Then		
		
			TFormPoint 0,0,0,light_fake\light_piv,Light\entity
			LightMesh Light\entity,light_fake\red,light_fake\green,light_fake\blue,light_fake\range,TFormedX(),TFormedY(),TFormedZ()
		End If
	Next
Next
End Function


Type dyfklight
	Field light_piv
	Field entity
	Field light
	Field red#
	Field green#
	Field blue#
	Field range#
	Field x#
	Field y#
	Field z#
End Type

Function create_dy_fklight(Name$,parent,r#,g#,b#,range#)
		dylight_fake.dyfklight = New dyfklight
		dylight_fake\light_piv = CreatePivot(parent)	
		dylight_fake\red#=r#
		dylight_fake\green#=g#
		dylight_fake\blue#=b#
		
		dylight_fake\range#=range#
End Function

Function update_dy_fklights()
	For dylight_fake.dyfklight = Each dyfklight
		
		For Light.fklightentity = Each fklightentity
			If (Light.fklightentity <> Null) Then		
		
			TFormPoint 0,0,0,dylight_fake\light_piv,Light\entity
			LightMesh Light\entity,dylight_fake\red,dylight_fake\green,dylight_fake\blue,dylight_fake\range#,TFormedX(),TFormedY(),TFormedZ()
		End If
	Next
Next
End Function



Warner(Posted 2010) [#4]
I'm a bit confused what you mean. But you can make a function that returns the newly created light:



Aussie(Posted 2010) [#5]
That is exactly what it is that i am trying to. But with my fake light.

I have tried this.
Type tlight
	Field strength
End Type

llight1.tlight = create_st_fklight(0,2,10,255,0,255,2)

Function create_st_fklight(x#,y#,z#,r#,g#,b#,range#).tlight()
;i keep geting expected end function before the brackets of .tlight() & if i remove them i get duplicate identifier. 
light.tlight = New tlight
   Return light
End Function

But i can't seem to get it to work


Matty(Posted 2010) [#6]
Function create_my_light.tlight(parameters)

myLight.tlight=new tLight
;set parameters accordingly
return myLight.tLight

End Function 




Midimaster(Posted 2010) [#7]
and also this is possible (with Matty's function create_my_light() ):
Dim lights.TLight(10)
Lights(0)=create_my_light.tlight(Parameters)
Lights(1)=create_my_light.tlight(Parameters)
......
Delete Lights(5)



Aussie(Posted 2010) [#8]
Thanks for the help everyone.
I have had an idea as to how to restructure the way i will create my fake lights. It may make it a bit easier to create & alow for parammeters to easily acessed to allow for colour change & light range to be changed. If it dosen't work i will keep on going the way i was.
Cheers. : )