[Fixed. Changed to attachMovie instead of Duplicate. Sorry for wasting your time]
Hi. I’m having trouble with a code in my game, but I’m not entirely sure whether this thread belongs here. Anyways…
Basically, when the enemy is attached, the _root.totalenemies goes up by 1. When it goes down, it subtracts by 1. Also when the enemy is loaded, the _root.enemyinstance goes up by one. The _root.enemyinstance is added onto the end of the enemy’s movieclip instance name (or it’s supposed to).
Now what the code is supposed to be doing it finding out whether or not there are least than 5, and if there are, load 1 enemy every two seconds. For some reason it only works once.
Below is the code.
Can anyone help me?
_root.totalenemies=0
_root.enemyinstance=0
_root.attachMovie(“greencubeenemy1”, “enemy”, 1, {_x:50, _y: 352});
function wait() {
if(_root.totalenemies<5){
for (a=_root.enemyinstance; a<=1; a++){
enemy.duplicateMovieClip(“enemy”+a, _root.getNextHighestDepth())
}
}
}
myTimer = setInterval(wait, 2000);
Thank you.