Hi, I’m working on the new stage, really looking forward to trying out the new character! But I’m having some problems with my code. I’m just Javascript.
loop {
var enemies = this.findEnemies();
var enemyIndex = 0;
var flag = this.findFlag("green");
var soldiers = this.findFriends();
var soldierIndex = 0;
if (flag) {
this.move(flag.pos);
this.pickUpFlag(flag);
}
else if (this.gold > this.costOf("soldier")) {
this.summon("soldier");
}
else {
while (enemyIndex < enemies.length) {
var enemy = enemies[enemyIndex];
enemyIndex++;
if (enemy.type !== "sand-yak") {
while (enemy.health > 0) {
this.attack(enemy);
while (soldierIndex < soldiers.length) {
var soldier = soldiers[soldierIndex];
soldierIndex++;
this.command(soldier, "attack", enemy);
}
}//End WHILE attack loop
}//End IF not sand-yak conditional
}//End WHILE enemies loop
}//End ELSE
}
How I see my code working is…
If there is a flag, move to it, pick it up
Also, if I have enough gold, then summon a solider (but only do this when not going after flag)
If there is no flag to move to, and if I dont have the gold to summon… THEN begin the enemy while loop
If the enemy is NOT a sand-yak, then attack it, and also command my soliders to attack it
The first problem I’m having is that my character will stop while moving to the flag, to attack an enemy. This causes problems in this level in the last zone, because she sees the enemies and tries to shoot them, but the wall prevents her from shooting them. So she just stands there blasting away at the wall.
Also, my soldiers are not attacking. I compared this to code from other levels but can’t figure out why they won’t attack.
Also, I guess since we travel from zone to zone, friends can’t follow along. So they just reappear in random locations in the next zone.
This seems like a fun level! Thanks for the help.