Progress towards next big Clashflash update:
AuthorMessage
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
Resolved.

if you need more info just ask.

Greetings

Reaven


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
because you're using tempEnemyhealth to store the health, it will be the same for all enemies. Why don't you use tempEnemy.health like you did with speed and turnRate?


"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
thanks.
my bad i think i missed the "."
but the hp doesnt work right.
Code:
_root.tempEnemy.health = _root.tempEnemy.health - 1;
//i think the script beneath this is the problem or above :P 
    if(_root.tempEnemy.health <= 0){
        trace("this works");
      destroyEnemy(tempEnemy);
      }

it should be destroyed after being hit like
3 times "the health" this script was placed in a function that makes the hittest work for the bullet.

Greetings

Reaven


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
it doesn't work because you're refering to just 1 enemy in this function which you seem to place in the root. It's confusing that you removed all the code you put in your first post because now it's hard to explain what you're doing wrong.

Iirc you had an array with enemies, so you need to check the health of every enemy in a for loop instead of checking that of just 1 in a root variable.


"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
de code again i tried find the problem but..

solved

hope you can help me further

greetigns

Reaven


picture
Myth
avatar
Administrator
Level: 99 - Posts: 477
Joined: Dec 9, 2006
what doesn't work exactly ?


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
You're probably calling the function updateEnemies() in an onEnterFrame loop right?

So what I think you're trying to do, considering what I can make of the story, is that you remove an enemy when the health of that enemy drops to 0. You're probably lowering enemy health using the function checkEnemyHitt() (which you didn't supply).

Now I don't see any reason for using the function destroyEnemy(). What'd be more effective is to do a check on enemy health in the checkEnemyHitt() function, and if hitpoints reach 0, destroy that enemy right then and there by referencing its index instead of the enemy itself. Kinda like this:

Code:
function checkEnemyHitt(wall:MovieClip) {
  for (var i:int=0; i<enemies.length; i++) {
    //.... your code for the hit checks
    //....
    // followed by a death check
    if (enemies[i].health <= 0) {
      destroyEnemy(i);
    }
  }
}

function destroyEnemy(enemyIndex:Number) {

  removeMovieClip(enemies[enemyIndex]);
  enemies.splice(enemyIndex,1);

  if(enemyrespawn == true){
    trace ("respawning")
    createEnemy(1, "typeB", "e2");
  } else {
    trace("not respawning");
  }

}



"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
its says [cant say this in english so sry about that..
kan klasse of inteface niet laden.
and heres the chekenemyhitt
Code:
function checkEnemyHitt(_enemy:MovieClip):Void
{
  
  for(var i = 0; i < enemyArray.length; i++)
  {
    
    var tempEnemy:MovieClip = enemyArray[i];
    
    
    if(deathwall.hitTest(tempEnemy))
    {
      destroyEnemy(tempEnemy);
    }
    if(player_mc.hitTest(tempEnemy))
    {
      _root.hud1.playerhp =_root.hud1.playerhp - 1;
          }
  }
}


but in a other chek il do the bullets.

Code:
function checkEnemyHit(_bullet:MovieClip):Void
{
  
  for(var i = 0; i < enemyArray.length; i++)
  {
    
    var tempEnemy:MovieClip = enemyArray[i];
    
    
    if(tempEnemy.hitTest(_bullet))
    {
      doSplatter(container_mc, tempEnemy._x+40, tempEnemy._y, numberOfSplatterParticles, splatterDistance, splatterIntensity, splatterSize);
      destroyBullet(_bullet);
      _root.hud1.score=_root.hud1.score + 1;
      _root.tempEnemy.health = _root.tempEnemy.health - 1;
    }
}
}


Greetings

Reaven


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
You're putting a variable called deathwall into the checkEmenyHitt() call in your update function. The function itself names that variable _enemy, that's how you've specified it since you put it like:

Code:
function checkEnemyHitt(_enemy:MovieClip):Void

while you do a hittest with a seemingly non existing variable you call deathwall within that same function. I presume you want to do a hittest with the clip that you put into the function:

Code:
function checkEnemyHitt(deathwall:MovieClip):Void



"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
o dont now exatcly what you mean.
deathwall is a movieclip.
if the enemy hittest it they are destroyed.


Greetings

Reaven


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
you don't see that what you did in your function call didn't make sense? you call the checkEnemyHitt with a variable called deathwall in the updateEnemies function. In the checkEnemyHitt function you have labeled that variable _enemy, while you do a hittest with a variable called deathwall.

The code doesn't make sense <.<


"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
Maybe, but it did work though.
I did a hittest with the deathwall i tried it on a other way but i didn't work.
Its a bit confusing.
and i used your code but i said cant load class or interface. confused

Greetigns

Reaven


picture
Crisis
avatar
Administrator
Level: 99 - Posts: 921
Joined: Dec 8, 2006
Oh right, I'm sorry about that. I used the type int which doesn't exist in AS2. You can change this:

Code:
for (var i:int=0; i<enemies.length; i++) {

into this:

Code:
for (var i:Number=0; i<enemies.length; i++) {



"The absence of rules is the enemy of art." ~Orson Wells
picture
reaven
avatarposts
Excelling Guardian
Level: 20 - Posts: 312
Joined: Dec 11, 2008
ok got the code but i see your using
function checkEnemyHitt(wall:MovieClip)
but i dont even have anything called wall
and for the same thing as "enemies"
which should i place in there? or what do i need to change to my script?

Greetings/Regards

Reaven


picture
Myth
avatar
Administrator
Level: 99 - Posts: 477
Joined: Dec 9, 2006
reaven said:
its says [cant say this in english so sry about that..
kan klasse of inteface niet laden.
and heres the chekenemyhitt
Code:
function checkEnemyHitt(_enemy:MovieClip):Void
{
  
  for(var i = 0; i < enemyArray.length; i++)
  {
    
    var tempEnemy:MovieClip = enemyArray[i];
    
    
    if(deathwall.hitTest(tempEnemy))
    {
      destroyEnemy(tempEnemy);
    }
    if(player_mc.hitTest(tempEnemy))
    {
      _root.hud1.playerhp =_root.hud1.playerhp - 1;
          }
  }
}



What crisis meant, is that you have a function named:
Code:
function checkEnemyHitt(_enemy:MovieClip):Void


You're passing the variable _enemy as a function parameter, while you're never use that variable anywhere. It's maybe best to do it like this:
Code:
function checkEnemyHitt(enemyArray:Array, obstacles:Array):Void


now you can double loop this. you can check for each enemy if it did hit any obstacle like the deathwall.

in untested some sort of semi-pseudo code it would look something like this:
Code:
// check enemy hittest
// enemyArray is full of enemy objects, the movieclip is stored in .clip
// like enemyArray.push({clip: movieClipReferenceVar, health: 5})
function checkEnemyHit(enemyArray:Array, obstacles:Array):Void {
  for (var i:int = 0; i < enemyArray.length; i++) {
    for (var j:int = 0; j < obstacles.length; j++) {
      if (enemyArray[i].clip.hitTest(obstacles[j])) {
        enemyArray[i].health--;
        // if enemy is dead
        if (enemyArray[i].health <= 0) {
          destroyEnemy(enemyArray[i]); // refer to destroyEnemy function
        }
        // remove obstacle
        removeObstacle(obstacles[j]); // refer to removeObstacle function
      }
    }
  }
}






picture
< Go to page: 1, 2 >
There are a total of 3152 Clashflash.com members who have posted 7266 articles. Our newest registered user is Hooooda7, welcome!
There are currently 15 users online of whom 0 logged in and 15 guest(s).
auto ban