Effects to all entities with same name

Blitz3D Forums/Blitz3D Beginners Area/Effects to all entities with same name

Sph!nx(Posted 2009) [#1]
Another one from me regarding entities.

I've build a simple model of a crystal that will represent the score item. I let the model be placed at the location of all the map limbs/children named 'item_score'.




Here is the code for that:

If CountChildren(map) > 0 

	For childcount = 1 To CountChildren(map)



item_score = GetChild(map,childcount)


If Instr(EntityName(item_score), "item_score") > 0 Then

	item_score_present$ = True
	
	; model
	item_score_model = LoadAnimMesh("content\models\item_score\item_score.b3d")
	PositionEntity item_score_model,EntityX(item_score),EntityY(item_score),EntityZ(item_score)
	ScaleEntity item_score_model,2,2,2
	EntityFX item_score_model,4
	EntityAlpha item_score_model,0.5
	
EndIf


	Next 

EndIf 



Now, I've simply put this in my maps loop code :

TurnEntity item_score_model,0,5,0



It works fine, but just for one of the items. The first placed in the map editor. How would I make it so, that all of the item_score_model will rotate/turn in-game and not just the one?


puki(Posted 2009) [#2]
You are re-using the handle 'item_score_model'; therefore it is basically pointing to one instance of the item.

If you want to do it this way then you can; however, you will need to turn each item at the point you first reference it - ie, for example, after you have scaled 'item_score_model' you can then turn it within your initial For/Next loop.

Depends on what you want to do - you can make each one unique by loading it into a type or array if you want - so that you can dynamically turn them in the future (if your game depends on it).


Sph!nx(Posted 2009) [#3]
Types and arrays, ey? Will dive into the docs on those two. Thanks!


Stevie G(Posted 2009) [#4]
You should really be using instancing, where you copyentity a template model which is loaded initially.

Also, you do not need arrays here. You could set up a pivot, ITEM_SCORE_PIVOT and when you create a new instance of the model, just parent it to the pivot for later access.

Global ITEM_SCORE_MODEL = LoadAnimMesh("content\models\item_score\item_score.b3d")

ScaleEntity ITEM_SCORE_MODEL, 2, 2, 2
EntityFX ITEM_SCORE_MODEL, 4
EntityAlpha ITEM_SCORE_MODEL, 0.5
HideEntity ITEM_SCORE_MODEL

Global ITEM_SCORE_PIVOT = CreatePivot()

If CountChildren(map) > 0 
	For childcount = 1 To CountChildren(map)
		item_score = GetChild(map,childcount)
		If Instr(EntityName(item_score), "item_score") > 0 Then
			tmp = CopyEntity( ITEM_SCORE_MODEL, ITEM_SCORE_PIVOT )
			PositionEntity tmp,EntityX(item_score),EntityY(item_score),EntityZ(item_score)
		EndIf
	Next 
EndIf


To update all the items

;to update
Function UpdateItemScore()

	For c = 1 To CountChildren( ITEM_SCORE_PIVOT )
		child = GetChild( ITEM_SCORE_PIVOT, c )
		TurnEntity child, 0,5,0
	Next

End Function


You could actually set up a rotation animation on all the entities using setanimseq etc... and all will be done during the updateworld() in your main render loop.

Stevie


Sph!nx(Posted 2009) [#5]
Thanks Stevie!! I will try to implement your code cause I find types and arrays still quite difficult to grasp. Thanks again!


nawi(Posted 2009) [#6]
Use TurnEntityChilds
Function TurnEntityChilds(ent,a#,b#,c#)
        d = CountChildren(ent)
	For c = 1 To d
		TurnEntity GetChild(ent,c),a,b,c
	Next
End Function



Aussie(Posted 2009) [#7]
Cool i was just looking for someting like this.

here is my code i could use some help with.
For ins=0 To ted_number_of_instances
	If ins_handle(ins)
		If Instr(Lower(ins_name(ins)),"refrence_cube") = True Then
	
		smkcube= CopyEntity (cube2)
		PositionEntity smkcube,EntityX(ins_handle(ins)),EntityY(ins_handle(ins)),EntityZ(ins_handle(ins))		

	End If
End If
Next


Types & functions

Function create_smoke()
	sm.smoker = New smoker
		sm\smoke=CopyEntity (smokesp,smkcube)
		RotateSprite sm\smoke,Rnd(360)
		sm\smokespeed#=.5
		sm\smokealpha#=2
		sm\scalex#=2
		sm\scaley#=2
		EntityParent sm\smoke,0
		PositionEntity sm\smoke,EntityX(smkcube),EntityY(smkcube),EntityZ(smkcube)
End Function

Function update_smoke()
	For sm.smoker = Each smoker
		sm\scalex#=sm\scalex#+.1
		sm\scaley#=sm\scaley#+.1
		sm\smokealpha#=sm\smokealpha#-.01
		MoveEntity sm\smoke,0,sm\smokespeed#,0
		ScaleSprite sm\smoke,sm\scalex#,sm\scaley#
		EntityAlpha sm\smoke,sm\smokealpha#
		If sm\smokealpha < 0
			FreeEntity sm\smoke
			Delete sm
	EndIf
Next
End Function 


My problem is trying to add a particle effect to all of the smkcubes. I can only apply the effect to 1 of them at the momment.
Any help would be greatly appreciated :)

Sorry for hijacking your post Sph!nx


Stevie G(Posted 2009) [#8]
For ins=0 To ted_number_of_instances
	If ins_handle(ins)
		If Instr(Lower(ins_name(ins)),"refrence_cube") > 0
			smkcube= CopyEntity (cube2)
			PositionEntity smkcube,EntityX(ins_handle(ins)),EntityY(ins_handle(ins)),EntityZ(ins_handle(ins))		
			create_smoke( smkcube )		
		End If
	End If
Next



Function create_smoke( Entity )
	sm.smoker = New smoker
		sm\smoke=CopyEntity ( Entity )
		RotateSprite sm\smoke,Rnd(360)
		sm\smokespeed#=.5
		sm\smokealpha#=2
		sm\scalex#=2
		sm\scaley#=2
		PositionEntity sm\smoke,EntityX( Entity , 1 ),EntityY( Entity, 1 ),EntityZ( Entity, 1 )
End Function




Aussie(Posted 2009) [#9]
Thanks Stevie G :)


Sph!nx(Posted 2009) [#10]
Sorry for hijacking your post Sph!nx

No problem! The more input, the better! I will take a look at the posts and see if it helps me!


Sph!nx(Posted 2009) [#11]
I've looked at this with all the hints from this thread but I can't seem to understand any of it.

Can someone pls write a small example with my code, provided in the first post?


Thanks a lot!


Stevie G(Posted 2009) [#12]
See post #4


Sph!nx(Posted 2009) [#13]
Last time I tried to implement it I probably did something terribly wrong. I will try it again! Thanks again!


Sph!nx(Posted 2009) [#14]
Again, I have no success. I tried different ways with making the entities like globals, but then the effects get mixed up.

Perhaps my setup needs a different approach. Here is my full source code if anyone wishes to take a look at it.


Any more help is very much appreciated!

Thanks

Sph!nx


Sph!nx(Posted 2009) [#15]
Could someone please incorporate the code, provided in post #4, into my source code for me? I've tried doing it myself with different approaches, without success. It's driving me mad! :(


I'll be very grateful if anyone could help me solve this! Thanks!


Aussie(Posted 2009) [#16]
Gday Sph!nx
I have had a go but am having problems myself. When i try implementing the code the screen just turns black but all the text appears. Don't know if i am putting it in the wrong place in your code. I am putting the first section of code where you load your map & the update function in your turnentity loop.


Sph!nx(Posted 2009) [#17]
Lol, thanks!

Yet a new side effect :P. I put all the action like update functions in the main map loop.


Aussie(Posted 2009) [#18]
Gday Sph!nx
How is your project coming allong?
I was just looking up some info on Gile[s] & noticed that you have it.
why not import your map into Gile[s], position pivots where you want your gems to be then setup custom properties. You can then use the include parseb3d.bb file to acess them.

The first thing you would need to do this, is setup a type in b3d. To do this you could do something like this.
type gem ; this is the name of your type
     field roty#,mesh,parent ;field is a pice of information you can acess within a type
end type


In Gile[s] you would setup custom properties for your pivots with something like this.
typegem
roty#=5


Then in the parseb3d.bb file you can acess your custom properties like this.
; Custom properties
	If (Instr(name$,"[PROPS]")<>0) And (Instr(name$,"[/PROPS]")<>0)
		newoffset	= Instr(name$,"[PROPS]",1)+7
		
		; Uncomment this if you need it
		;
		;DebugLog "Custom properties for: "+Left$(name$,newoffset-9)
		
		g.gem = Null ;Here is where you enter the name of your type. All types must start with a .Name
		
		Repeat
			;
			; Text offset for the next line
			offset		= newoffset+1
			newoffset	= Instr(name$,Chr$(10),offset)	
						
			;
			; The text on this line
			in$ = Mid$(name$,offset,newoffset-offset)
	
			; Jump out of the loop
			; at the end of the properties
			If in$ = "[/PROPS]"
				Exit
			End If
			
			;
			; Get the keyword
			key$ = ""
			offset = Instr(in$,"=")
			If offset
				key$		= Lower(Left$(in$,offset-1))
				content$	= Right$(in$,Len(in$)-offset)
			Else
				key$	= Lower(in)
			End If
			
			;
			; This is where you add your own stuff!
			; The things used in this example, are just that: examples
			; You can do anything!
			;
			Select key$
				Case "typegem":
					g.gem = New gem
					g\parent = entity
					g\mesh=LoadMesh("your_gem_mesh_",g\parent) ;this loads your mesh & parents it to the pivot you created in Gile[s]

				Case "roty#":
					If Not (g = Null)
						g\roty# = GetCSV(content,1) ; here is your field roty# all fields must have \field
					End If
					

			End Select
			
			; Uncomment this to
			; print the property to the debug log
			 DebugLog "  Property: "+Chr$(34)+in$+Chr$(34)
	
		Forever
	End If
	
	;
	; Go through the children of this entity
	children = CountChildren(entity)
	For child = 1 To children
		ParseB3D(GetChild(entity,child))
	Next

This is only a section of the file so you will have to have a look at the whole file to see what i have done.

Next you would need to setup a function to update your gems.
function update_gems()
     for g.gem=each gem
          g\roty#=g\roty#+5
          rotateentity g\mesh,0,g\roty#,0
end function


Then you would just call on the update function in your loop.

Dont forget to call on this function when you load your map. ParseB3D(The name of your map with custom properties).
I was playing around with this earler & forgot to use it then it took me about an hour to find out why nothing would work. He he.
Hope this helps.
I am still a bit of a noob so if anyone has any comments or corrections please correct me.:)


Sph!nx(Posted 2009) [#19]
How is your project coming allong?

Well, this part is really keeping a hold on everything. Understanding this is needed for any other kind of progress. Thanks for asking!

And ... WOW, thanks! Just came home from work and a bit too tired to get into coding right now, but I'm off next Thursday and then I'll dive into this.

I will let you know how things will go. Thanks again m8!


Sph!nx(Posted 2009) [#20]
Thanks again Aussie,

The setup you provided me is definitely an option, but I would really like to use 3D world studio for world creation and entity placement because the end goal of this engine is for a small team to work on an actual game. The team is already familiar with 3DWS. Using too many editors would only complicate things I guess...

Isn't there a way to use your types setup in my current code, which only needs 3DWS to build worlds for?


Aussie(Posted 2009) [#21]
Gday Sph!nx
I have been flat out at work the last few days & only just saw this post. I dont know much about 3DWS but if there is a custom properties option i would say that you would be able to do the same thing with it.

I am sure that there is a way to assign a type to a mesh from your code but with my level of experience i am unsure how this would be done. You may be able to do it within your.
For childcount = 1 To CountChildren(map)

and then use your
If Instr(EntityName(item_score), "item_score") > 0 Then
item_score_model = new gem


I don't know if it can be done like this though.
Its been a long few days so i hope this makes sence. :)


Sph!nx(Posted 2009) [#22]
Thanks Aussie, I know... work is sucking up my time too! You've been a great help so far.

I do have some time today and tomorrow to work on my engine again. I will take a look at all your tips and try see how I can incorporate them into my own code!

Thanks again, m8!


Sph!nx(Posted 2009) [#23]
I've been struggling further, again with all kinds of outcomes but nothing near what I want to achieve.

What I did understand from all of you guys is that i need to change the setup a little.

I got now:
1) a loop that finds the maps children and creates the model. 2) the actions in the main loop are directly tied to that model.

What I think you guys are trying to tell me:
1) create the 'template' entity. 2) duplicate the 'template' inside the map child loop 3) put the action inside another function and start that function inside the main map loop, correct?

Question: would the pre-created template be as a type or something else?

Are there any good (simple) examples regarding entities and 3D world studio?


Thanks a lot!


Aussie(Posted 2009) [#24]
Gday mate Just cracked it.

If you still have all of your original code here it is.

in your map.bb add this just under you "Global item_score_model"
Type gem
	Field mesh
End Type

Function Create_gem(parent)
	g.gem = New gem
	g\mesh = CopyEntity (item_score_model)
	PositionEntity g\mesh,EntityX(parent),EntityY(parent),EntityZ(parent)
	ScaleEntity g\mesh,2,2,2
	EntityFX g\mesh,4
	EntityAlpha g\mesh,0.5
End Function

Function update_gem()
	For g.gem = Each gem
	TurnEntity g\mesh,0,5,0
	Next
End Function


in your item_score_load.bb Change it to this
;==========================================================================================
;
; Enititie item_score load
;
;==========================================================================================

item_score = GetChild(map,childcount)


If Instr(EntityName(item_score), "item_score") > 0 Then

	item_score_present$ = True
	
	; model
	item_score_model = LoadAnimMesh("content\models\item_score\item_score.b3d")
	
	Create_gem(item_score)
	
	
EndIf


then in you item_score_loop.bb change to this
;==========================================================================================
;
;	item_score loop
;
;==========================================================================================
update_gem()


And it should work.


Sph!nx(Posted 2009) [#25]
Thanks Aussie but when I try to run it I get an "entity does not exist" error...

I've uploaded the new sources with your code added. I would be very grateful if you would take a look at it! (If you need any help with something... dunno, game content, hosting, whatever... just say so!)


Edit :
Forgot the link to the source :P
http://www.deved-portal.com/deved3d/ftp/wip/v0.4/program.rar


Aussie(Posted 2009) [#26]
All you need to do is in your map.bb is make a "Global Item_score_model"

(If you need any help with something... dunno, game content, hosting, whatever... just say so!)


Thanks for the offer mate. I had my fair share of help from the people here so im just happy i could help someone else out. :)


Sph!nx(Posted 2009) [#27]
ohw yes, I see now. I put it under global item_score and forgot the _model :P

It works perfectly! Thanks a lot m8! Now I can focus on the next thing. I can now read and use the map child name, next thing is the childs properties.

Thanks again, this has been a major problem for me!


Aussie(Posted 2009) [#28]
No worries.

If you mean by "childs properties" what the value of the score will be when the player collects a gem. All you need to do is add more fields to your gem type. ie( score,health,damage it can be whatever you like.)
Here is something i was testing a while ago it might help you out. Just have a look through the code & you should be able to figure out what is going on.
Graphics3D 800,600,0,2

SetBuffer BackBuffer()

Global cone
Global chase_cam
Global sphere1
Global sphere2
Global plane
Global pk.pickup
Global p.player
Global en.enemy

Global player_hit=0
Global player_col=1
Global ground_col=2
Global score_col=3
Global enemy_col=4
Global player_col2=5

Global playerscore=0
Global playerhealth=100

Collisions player_col,ground_col,2,2
Collisions player_col,enemy_col,2,0
Collisions enemy_col,player_col,2,0
Collisions player_col2,ground_col,2,2


tex=CreateTexture(32,32,8)
	ScaleTexture tex,2,2
	SetBuffer TextureBuffer (tex)
	Color 0,0,54:Rect 0,0,32,32
	Color 0,0,255:Rect 0,0,32,32,False
SetBuffer BackBuffer()

plane=CreatePlane()
	EntityTexture plane,tex
	PositionEntity plane,0,-1,0
	EntityFX plane,1
	EntityType plane,ground_col
	
cone=CreateCone()
	HideEntity cone
		
chase_cam=CreateCamera()
	PositionEntity chase_cam,0,1,-5
	
sphere1=CreateSphere(3)
	ScaleEntity sphere1,.5,.5,.5
	EntityColor sphere1,0,0,255
	EntityFX sphere1,1
	HideEntity sphere1
	
sphere2=CreateSphere()
	ScaleEntity sphere2,.5,.5,.5
	EntityColor sphere2,255,0,0
	EntityFX sphere2,1
	HideEntity sphere2

	

create_pickup()
create_player()
create_enemy()


While Not KeyDown (1)

update_player()

UpdateWorld
RenderWorld
Color 0,255,0
Text 0,0, "HEALTH: "+ playerhealth
Text 0,20, "SCORE: "+ playerscore
Flip
Wend
End

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Function update_chase_cam(camera,entity,cam_final,speed#=30)
	PointEntity camera,Cam_final
	MoveEntity camera,0,0,EntityDistance#(Cam_final,camera)/speed
	PointEntity camera,entity
	RotateEntity camera,EntityPitch#(entity),EntityYaw#(entity),EntityRoll#(entity)
End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Type player
	Field cam_final,player_mesh,player_v#,player_grav#,player_health,player_score
End Type

Function create_player()
	p.player = New player
		p\player_mesh=CopyEntity(cone)
		p\cam_final=CreatePivot(p\player_mesh)
		PositionEntity p\cam_final,0,2,-9
		EntityColor p\player_mesh,0,255,0
		PositionEntity p\player_mesh,0,0,0
		EntityType p\player_mesh,player_col
		p\player_score=0
		p\player_health=100
		p\player_v#=0
		p\player_grav#=-.1
End Function

Function update_player()
	For p.player = Each player
	If KeyDown(200) Then p\player_v#=p\player_v#+.02
		If p\player_v# > 1 p\player_v#=1
		If Not KeyDown(200) Then p\player_v#=p\player_v#-.05
		If p\player_v# < 0 p\player_v#=0
	If KeyDown(203) TurnEntity p\player_mesh,0,2,0
	If KeyDown(205) TurnEntity p\player_mesh,0,-2,0
	MoveEntity p\player_mesh,0,0,p\player_v#
	TranslateEntity p\player_mesh,0,p\player_grav#*2,0
	update_chase_cam(chase_cam,p\player_mesh,p\cam_final,10)
	If playerhealth=0
	FreeEntity p\player_mesh
	Delete p
	EndIf
	For pk.pickup = Each pickup
		If EntityDistance (p\player_mesh,pk\score_mesh) < 1.5 Then
			playerscore=playerscore+pk\score 
			FreeEntity pk\score_mesh
			Delete pk
		EndIf 
	For en.enemy = Each enemy
		If EntityCollided (p\player_mesh,enemy_col)
			EntityType p\player_mesh,player_col2
			playerhealth=playerhealth-en\enemy_damage
			MoveEntity p\player_mesh,0,1,-9
			p\player_v#=0
			EntityType p\player_mesh,player_col
		If EntityCollided (en\enemy_mesh,player_col)
			ResetEntity p\player_mesh
			playerhealth=playerhealth-en\enemy_damage
			MoveEntity p\player_mesh,0,2,-9
			p\player_v#=0
		EndIf
		EndIf
		Next	
	Next
Next
End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Type pickup
	Field score_mesh,score
End Type


Function create_pickup()
	For pkup= 0 To 100
		pk.pickup=New pickup
			pk\score_mesh=CopyEntity(sphere1)
			PositionEntity pk\score_mesh,Rnd(-200,200),-.5,Rnd(-200,200)
			pk\score=5
	Next
End Function


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	

Type enemy
	Field enemy_mesh,enemy_damage
End Type

Function create_enemy()
	For enm= 1 To 50
		en.enemy = New enemy
		en\enemy_mesh = CopyEntity(sphere2)
		EntityType en\enemy_mesh,enemy_col
		PositionEntity en\enemy_mesh,Rnd(-200,200),-.5,Rnd(-200,200)
		en\enemy_damage=5 
	Next
End Function



Sph!nx(Posted 2009) [#29]
Thanks m8! I do need that info to add more effects to the individual entities, so you just gave me another push in the right direction!

But what I meant with 'children properties' is actually the settings done in 3D world Studio. Those 'properties' are in reality just extra parts in the string (name) of the specified children. Like angles, size, etc.

In the map editor, one can add extra properties to one entity, that needs to be 'parsed' in the code. There are plenty of examples (i though) so I will try that first before adding real actions to the entities (like player contact etc.)

I though I downloaded an example a while back but cant find it now :P I will browse the forums a little more!


Sph!nx(Posted 2009) [#30]
one last question :P

I've properly setup collision, that works. Now i want to so when the player (ball) collides with it, the score items gets destroyed. Tried different things in both the score code and the player code... How would I do this?

Thanks!


Aussie(Posted 2009) [#31]
You would be better off useing entity distance for pickups.

Copy & paste the code i last posted & have a look in the "update_player" function at "For pk.pickup"


Sph!nx(Posted 2009) [#32]
update_player function, ey? I will try again ;)


Sph!nx(Posted 2009) [#33]
I've been puzzling away again. I really need a concrete example to understand this I'm afraid.

I simple wish that when the ball (player) connects with the gem(item_score), the gem disappears.

I own DB-pro as well and tried those forums too for help. They are not that helpful so I came back here. Heck, I even offer compensation, if you catch my drift, but they keep everything secret or they are all too lazy to share knowledge. I've always got great help from here, so I'm back!

I only need this little peace of the code. I've studied the AdvancedSceneLoading example, but can't seem to figure it out.

I'm at the end of my options here and I'm struggling now for months. Can somone please write me an example in my code?

If I eventually understand this I will write a simplified version for everyone with the same problems.

Here is the complete source code and files: http://www.deved-portal.com/deved3d/ftp/wip/development/program.rar

Please, I really need to understand the .b3d loading with limbs, or children, and individual actions for all the children.

If this would be a big job to do, please contact me through sphinx019@... and I'm willing to talk about payment or other form of compensation, like free web hosting.

As you can see, I've become desperate and any help is welcome!


Warner(Posted 2009) [#34]
Maybe I'm not understanding completely what you want, but it is a long thread and I didn't entirely read it. Hopefully this helps?



Kryzon(Posted 2009) [#35]
Sph!nx, the problem is that in your code you are checking if the gem collided with the player, when it should be the other way around (since you declared your Collisions to be Player -> Gems).

So, in order to fix your code, you need to change two things:

1 - Declare the Player (which holds the collision pivot) as a global in your Map.BB. We need to declare the Player pivot as a global because we are going to reference it from the Update_Score() function.

[...]

; Collision index
Const world_col=1
Const player_col=2
Const item_score_col=3
Global player  <-----------------


2 - Change your Update_Score() function to this one:


; Update score
Function update_score()
	
	For g.score = Each score
	    
	    TurnEntity g\mesh,0,5,0
	
	    If EntityCollided(player,item_score_col) Then
	
	       For I = 1 To CountCollisions(player)
	
	           If g\mesh = CollisionEntity(player,I) Then 
	
	              FreeEntity g\mesh    
	              Delete g
	
	           EndIf
	
	       Next
	
	    EndIf 
	
	Next 
	
End Function

Which effectively checks to see if the player collided with the gems, not the gems collided with the player. It's a small detail. Now you now :D

Good luck with your engine.


Sph!nx(Posted 2009) [#36]
Wow, thanks guys! :-D

Kryzons tip helped me a lot. Still, sometimes I collide and it successfully disappears but other times it ends my game and gives me a "object does not exist" error.

Thanks again!


(Now I remember again why I love Blitz, Its the great support! Can't understand why the DB-pro community is so different.)


Kryzon(Posted 2009) [#37]
Oh, don't mention it :)

Ahhh, about the error... you see, sometimes the gem will be deleted but the For...Next loop iterating through the collisions from the player will still try to reference it, thus giving that "object does not exist" error (because it deleted the Type but is still trying to use it).
It's a logical error, I didn't even notice it.

Doing this should fix it:
; Update score
Function update_score()
	
	For g.score = Each score

	    Delete_Type = False

	    TurnEntity g\mesh,0,5,0
	
	    If EntityCollided(player,item_score_col) Then
	
	       For I = 1 To CountCollisions(player)
	
	             If g\mesh = CollisionEntity(player,I) And Delete_Type = False Then 
	
	                FreeEntity g\mesh    
	                Delete_Type = True
	
	             EndIf
	
	       Next
	
	    EndIf
 
	    If Delete_Type = True Then Delete g

	Next 
	
End Function

We mark the Type Instance for deletion, instead of deleting it right there.

EDIT: Improved it a bit. Hope it works.


Sph!nx(Posted 2009) [#38]
It works! Thanks a lot!

I will now try to add the code with different effects for different objects. When I need some more help, though this was my major obstacle, I will post it here! Also, when I've completed the base engine, I will post it for everyone to learn from.

Everybody here, who genuinely tried to help is welcome to get hosting, or file mirroring from me. Just email me at the above posted address and I will be more that happy to help out. That's my way of offering help, since coding wise, I'm still a a bit of a n00b :P

If I could, I'd buy you all a round of beers!


Sph!nx(Posted 2009) [#39]
Hello everybody!

Back at this again. Before I will proceed with adding entities I am improving the overal loading code with the 'advancedsceneloadinginb3d' file.

Here is what I have so far:
; Initial loading:
AppTitle "Blitz3D"
HidePointer()

Graphics3D 800,600,0,2
SetBuffer BackBuffer()

; Load and run the map.bb:
;Include "code\map.bb"

;==================================== Initial setup ========================================

mapfile$=CommandLine()
mapfile$=Replace(mapfile,Chr(34),"")
mapfile$=Trim(mapfile$)
;If mapfile$="" End

; Global IDs:
Global cam

; Collision settings
; types:
Const COLLISIONTYPE_PLAYER=1
Const COLLISIONTYPE_BULLET=2
Const COLLISIONTYPE_BRUSH=3
Const COLLISIONTYPE_MESH=4

; Collision relations
Collisions COLLISIONTYPE_PLAYER,COLLISIONTYPE_BRUSH,2,2

; create the camera
cam=CreateCamera()
CameraRange cam,1,10000
CameraZoom cam,1.4
RotateEntity cam,45,0,0
MoveEntity cam,0,0,-1000
EntityType cam,COLLISIONTYPE_PLAYER
EntityRadius cam,32

; Mouse settings:
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
mousespeed#=0.4
cameraspeed#=10
camerasmoothness#=4

; load the map files:
mapfile$="content\maps\map01\map01.b3d"
; Activate the loadworld function with the defined .b3d
map=LoadWorld(mapfile$)
; DebugLog:
If Not map RuntimeError "Failed to load map "+Chr(34)+mapfile+Chr(34)+"."


;=================================== Main map loop ========================================

While Not KeyHit(1)

	; 3D STUFF
	
	;Camera mouse controls
	mx#=CurveValue(MouseXSpeed()*mousespeed,mx,camerasmoothness)
	my#=CurveValue(MouseYSpeed()*mousespeed,my,camerasmoothness)
	
	; Camera movement controls
	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	pitch#=EntityPitch(cam)
	yaw#=EntityYaw(cam)
	pitch=pitch+my
	yaw=yaw-mx
	If pitch>89 pitch=89
	If pitch<-89 pitch=-89
	RotateEntity cam,0,yaw,0
	TurnEntity cam,pitch,0,0
	
	cx#=(KeyDown(205)-KeyDown(203))*cameraspeed
	cz#=(KeyDown(200)-KeyDown(208))*cameraspeed
	MoveEntity cam,cx,0,cz


	;==============================================================
	UpdateWorld()
	RenderWorld()
	;==============================================================

	; 2D STUFF
	
	Flip

Wend


; =================================== LOADWORLD ============================================

Function LoadWorld(file$)

	map=LoadAnimMesh(file) 
	If Not map Return
	
	
	world=CreatePivot() 
	meshes=CreatePivot(world)
	renderbrushes=CreateMesh(world) 
	collisionbrushes=CreatePivot(world)
	pointentities=CreatePivot(world) 
	solidentities=CreatePivot(world)
	 
	EntityType collisionbrushes,COLLISIONTYPE_BRUSH
		
	For c=1 To CountChildren(map) 
	
		node=GetChild(map,c) 
		
		classname$=Lower(KeyValue(node,"classname")) 
		DebugLog "Loading "+Chr(34)+classname+Chr(34)+"..." 
		Select classname 
			
		; world
		Case "mesh" 
			EntityParent node,meshes 
			EntityType node,COLLISIONTYPE_MESH 
			c=c-1

		Case "terrain" 
			EntityType node,COLLISIONTYPE_BRUSH 
			EntityParent node,collisionbrushes 
			c=c-1
			
		Case "brush" 
			AddMesh node,renderbrushes 
			EntityType node,COLLISIONTYPE_BRUSH 
			EntityAlpha node,0 
			EntityParent node,collisionbrushes 
			c=c-1

			
		;Camera start position point entity 
		Case "playerstart" 
			angles$=keyvalue(node,"angles","0 0 0") 
			pitch#=piece(angles,1," ") 
			yaw#=piece(angles,2," ") 
			roll#=piece(angles,3," ") 
			If cam 
				PositionEntity cam,EntityX(node),EntityY(node),EntityZ(node) 
				RotateEntity cam,pitch,yaw,roll 
				EndIf
				
			End Select
 
	Next
	 
	FreeEntity map 
	Return world 
	
End Function 

;End program:
;End

; ============================== reading functions =========================================

Function Piece$(s$,entry,char$=" ")
While Instr(s,char+char)
	s=Replace(s,char+char,char)
	Wend
For n=1 To entry-1
	p=Instr(s,char)
	s=Right(s,Len(s)-p)
	Next
p=Instr(s,char)
If p<1
	a$=s
	Else
	a=Left(s,p-1)
	EndIf
Return a
End Function

Function KeyValue$(entity,key$,defaultvalue$="")
properties$=EntityName(entity)
properties$=Replace(properties$,Chr(13),"")
key$=Lower(key)
Repeat
	p=Instr(properties,Chr(10))
	If p test$=(Left(properties,p-1)) Else test=properties
	testkey$=Piece(test,1,"=")
	testkey=Trim(testkey)
	testkey=Replace(testkey,Chr(34),"")
	testkey=Lower(testkey)
	If testkey=key
		value$=Piece(test,2,"=")
		value$=Trim(value$)
		value$=Replace(value$,Chr(34),"")
		Return value
		EndIf
	If Not p Return defaultvalue$
	properties=Right(properties,Len(properties)-p)
	Forever
End Function


;====================================== Entity functions ===================================

; mouse curve functions:
Function CurveValue#(newvalue#,oldvalue#,increments )
If increments>1 oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
If increments<=1 oldvalue=newvalue
Return oldvalue#
End Function



My first problem is that the terrain collision does not work. Anybody knows why?


Sph!nx(Posted 2009) [#40]
I've also tried to make it its own collision type, but with no result. The camera keeps flying through the terrain. The above code is the complete code, but if anyone requires the complete sources with content, just let me know!

Any help is appreciated!
Thanks!


Sph!nx(Posted 2009) [#41]
I found it myself! Here is the solution for anybody with the same problem:

After digging in a program called Giles, I noticed the terrain is divided into sectors. The make the collision work for all I had to alter the type for it. I added 'true' behind it to make it work.

Example:
Case "terrain" 
			EntityParent node,collisionbrushes 
			EntityType node,COLLISIONTYPE_BRUSH, True
			c=c-1
Yay!