Reaping Fire Help


#1

Hello all,

In this level, my hero just stands still and does nothing. Can someone point out where I messed up? Thanks!

function chooseStrategy() {
    var enemies = hero.findEnemies();
    // If you can summon a griffin-rider, return "griffin-rider"
    if(hero.gold >= hero.costOf("griffin-rider")){
      return "griffin-rider";
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
for(var i=0;i<enemies.length;i++){
    var distance = hero.distanceTo(enemy);
    var flyer= enemies[i];
     if(flyer && distance < 30 ){
    return "fight-back";
     }

    // Otherwise, return "collect-coins"
    else{
        return "collect-coins";
    }
}
}

function commandAttack() {
    // Command your griffin riders to attack ogres.
    var enemy= hero.findNearest(hero.findEnemies());
    if(enemy && enemy.type == "ogre"){
        hero.command(griffin-riders,'attack',enemy);
        }
}

function pickUpCoin() {
    // Collect coins
    var coin= hero.findNearest(hero.findItems());
    if(coin){
        hero.move(coin.pos);
        }
}

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy && enemy.type==fangriders){
        hero.attack(enemy);
        }
}

while(true) {
    commandAttack();
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"){
        commandAttack();
        }
        if(strategy == "fight-back"){
            heroAttack();
            }
            if(strategy =="collect-coins"){
                pickUpCoin();
                }
}


#2

when the strategy returned “griffin-rider” you were supposed to summon one griffin-rider. You also didn’t define griffin-riders. And, if they were going to attack,you had to show that a commandable unit was standing there.


#3

@Seojin_Roy_Lee I guess you got your account back. Congrats :smile:


#4

Right (I still don’t like 20 character.)


#5

Thanks for replying!

I changed my code and tweaked it a bit and got this:

function chooseStrategy() {
    var enemy = hero.findNearest(hero.findEnemies());
    // If you can summon a griffin-rider, return "griffin-rider"
    if(hero.gold >= hero.costOf("griffin-rider")){
      hero.summon("griffin-rider");
    }
    // If there is a fangrider on your side of the mines, return "fight-back"
  else if(enemy){
      var distance = hero.distanceTo(enemy);
     if(enemy && distance < 10 ){
    return "fight-back";
     }
  }

    // Otherwise, return "collect-coins"
    else{
        return "collect-coins";
    }
}


function commandAttack() {
    // Command your griffin riders to attack ogres.
    var enemy= hero.findNearest(hero.findEnemies());
    var friend = hero.findByType('griffin-rider');
    if(enemy && enemy.type == "ogre"){
        hero.command(friend,'attack',enemy);
        }
}

function pickUpCoin() {
    // Collect coins
    var coin= hero.findNearest(hero.findItems());
    if(coin){
        var coinPos={'x':coin.pos.x,'y':coin.pos.y};
        hero.move(coinPos);
        }
}

function heroAttack() {
    // Your hero should attack fang riders that cross the minefield.
    var enemy = hero.findNearest(hero.findEnemies());
    if (enemy && enemy.type=='fang-riders'){
        hero.attack(enemy);
        }
}

while(true) {
    commandAttack();
    var strategy = chooseStrategy();
    // Call a function, depending on what the current strategy is.
    if (strategy == "griffin-rider"){
        commandAttack();
        }
      else  if(strategy == "fight-back"){
            heroAttack();
            }
         else if(strategy =="collect-coins"){
                pickUpCoin();
                }
}

This time my hero moves and picks up coins, summons 1 griffin rider, and stops moving when an enemy comes


#6

You have some weird indentations going on. The error is probably because of the indentations.

Also how come you have the commandAttack(); before the strategy variable, outside the if loops?


#7

I was going to say that…


#8

good question lol. it was already there, and i guess i forgot to delete it. as for the weird indentations, when I hit “enter” that’s where the curser went to i guess. I"ll try to fix everything =]


#9

multiple times, when I was about to finish a post, I accidentally deleted the whole thing, so then I either gave up or I wrote the whole thing again.


#10

Will check new code …
In first code you did’t summon griffin riders. In second you don’t have ‘griffin-rider’ strategy.


#11

needs to be edited the 3rd time, spelling error.