Worldtimer

Blitz3D Forums/Blitz3D Beginners Area/Worldtimer

Buggy(Posted 2006) [#1]
Why doesn't this work correctly? I use the same timing system for many things in many of my programs, and yet here it seems broken.

Here is the relevant code:
;CREATES NEW EXHAUST PARTICLES, MOVES AND FADES THE PARTICLES, AND EVENTUALLY DELETES THEM
Function exhaust()

	;since each ship gives off exhaust...
	For ship.ship = Each ship
	
		f = 0
	
		;finds the exhaust generators
		For exhaustGeneratorSpecs.exhaustGenerator = Each exhaustGenerator

			f = f + 1

			DebugLog f + ": " + (worldtimer - (ship\exhaustGeneratorSpecs\timer + 1000))
	
			;if it's time to create a new exhaust particle, do so!
			If worldtimer > (ship\exhaustGeneratorSpecs\timer + 1000)
				
				;creates the new particle
				exhaust.exhaust = New exhaust
			
					;instead of loading it each time, copy it to the generator point
					exhaust\entity = CopyEntity(exhaustParticle, ship\exhaustGeneratorSpecs\entity)
					
					;free's its child-hood so that it moves irrelevant of the ship
					EntityParent exhaust\entity, 0
				
					exhaust\dx# = 0
					exhaust\dy# = 0
					exhaust\dz# = 0
					exhaust\exhaustColor = 155
				
					;a nice hue
					EntityColor exhaust\entity, exhaust\exhaustColor + 100, exhaust\exhaustColor, 0
				
				ship\exhaustGeneratorSpecs\timer = worldtimer
			
				DebugLog f + ": " + (worldtimer - (ship\exhaustGeneratorSpecs\timer + 1000))

			
			EndIf
		
		Next
		
	Next
	
	;finds each exhaust particle
	For exhaust.exhaust = Each exhaust
	
		;moves the particle and has it's color fade
		MoveEntity exhaust\entity, exhaust\dx, exhaust\dy, exhaust\dz
		EntityColor exhaust\entity, exhaust\exhaustColor, exhaust\exhaustColor, 0
		
		exhaust\exhaustColor = exhaust\exhaustColor - 10
		
		;if it's black, delete it.  Duh.
		If exhaust\exhaustColor < 0
			
			FreeEntity exhaust\entity
			Delete exhaust
			
		EndIf
		
	Next
	
End Function


The Relevant Part of the Debug Log Reads:
1: -37
2: -37
1: -21
2: -21
1: -4
2: -4
1: 13
1: -1000
2: -1000
1: -984
2: -984


As can be seen, only one particle is emitted. Why? Why does the second exhaust generator's timer reset itself when it doesn't create the particle?


b32(Posted 2006) [#2]
I find it difficult to exactly understand, but maybe it is the two types of exhaustGeneratorSpecs that is doing this. The for variable is exhaustGeneratorSpecs.Exhaustgenerator and the timer-reset uses ship\exhaustgenerator


Buggy(Posted 2006) [#3]
Sorry, let me clarify the inheritence. Player -> Fighter -> Ship -> ExhaustGenerator.

As this is only a portion of the code, it must be difficult to understand. The exhaustGenerators are pivots where the ship's fiery exhaust will come out of.


b32(Posted 2006) [#4]
I thought the problem was caused by resetting ship\exhaustGeneratorSpecs\timer = worldtimer, which is part of the ship-type. Instead, it could be better to reset exhaustGeneratorSpecs\timer, so every generator has it's own timer ?


Buggy(Posted 2006) [#5]
That's probably (and hopefully) it! Thanks so much!

Edit: It verks! It verks!