If/then statement problem

Blitz3D Forums/Blitz3D Programming/If/then statement problem

Chad(Posted 2008) [#1]
Okay, I have a If/then statement which works great, except when I try to create a particle to work with it. In the debug, it says that there is no entitynamed that, which, if I create the emitter somewhere else and just let it run, it works fine.

Here's the If/Then statement without the create particle:

For thisbullet = Each bullettype				;iterate through all of the bullets
  If CountCollisions(thisbullet\entityhandle) > 0		;check if bullet collided with something
    enemyhit = EntityCollided(thisbullet\entityhandle, 3)	;note which enemy (entity type 3) bullet collided with (if any)
    If enemyhit > 0 Then KillBadGuy(enemyhit)	:  PlaySound(explosion)	: PlaySound(torpedoimpact)
		FreeEntity thisbullet\entityhandle				;delete the bullet mesh
    Delete thisbullet						;delete the bullet
  EndIf
Next


And now my attempt to create a particle inside this if/then statement! (Notice, this exact createParticleEmitter code inserted here works great when I put it anywhere else, just does not work here. The sounds also work, so I don't think that is a problem.

For thisbullet = Each bullettype				;iterate through all of the bullets
  If CountCollisions(thisbullet\entityhandle) > 0		;check if bullet collided with something
    enemyhit = EntityCollided(thisbullet\entityhandle, 3)	;note which enemy (entity type 3) bullet collided with (if any)
    If enemyhit > 0 Then KillBadGuy(enemyhit)	:  PlaySound(explosion)	: PlaySound(torpedoimpact) :
			particleemitter5=CreateEmitter_explosion() :
			ShowEntity particleemitter5 :
			PositionEntity particleemitter5,0,0,0
		FreeEntity thisbullet\entityhandle				;delete the bullet mesh
    Delete thisbullet						;delete the bullet
  EndIf
Next


Does anyone know what I'm doing wrong?

Should I create it before where it works, and then hide it until I need it? Or am I doing something else wrong? I want it to be universal that no matter where the bullets hit, the explosion particle is created.

Thanks,
Chad


Chad(Posted 2008) [#2]
Okay, I used my idea and used "HideEntity" and "ShowEntity" for when it wants.

However, the explosion happens at 0,0,0, which, is what I have as the position.

Should I use variables to create the particle where the bullet hits? If yes, how so? Are there any other ways?


Floyd(Posted 2008) [#3]
The indentation suggests that you are mixing up the two kinds of If statement.

The block version has the form
If condition
   ; A block of statements
   ; goes here
End If

The single-line version does not have End If, it ends at the end of the line.
If condition Then statement1 : statement2 : etc.    ; and it ends here.

Note the word Then is optional.


Wayne(Posted 2008) [#4]



Chad(Posted 2008) [#5]
Okay, Wayne, I got yours working, however, it still creates the emitter at 0,0,0 instead of where the bullet hits.

Should we use variables for the positionentity of the emitter so whereever it hits it creates and positions it at that location?


Chad(Posted 2008) [#6]
Parenting the emitter to the bullet doesn't work either.

I thought that maybe if I parented the particleemitter to the bullet, that when it hit it would play, but that doesn't work either.


Stevie G(Posted 2008) [#7]
Once you've parented it , make sure you use positionentity emitter 0,0,0 so that it's positioned exactly where the bullet is in global space.

or just do ...

positionentity emitter, entityx( thisbullet\entityhandle , 1 ) , entityy( thisbullet\entityhandle , 1 ), entityz( thisbullet\entityhandle , 1 )

Stevie