Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] The Two Flowers Help


#1

Getting error on line 16 methodname has a problem how do i fix this thanks

// If the peasant is damaged, the flowers will shrink!

function summonSoldiers() {
    friends = hero.findFriends();
    if (hero.gold >= hero.costOf("soldier")) {
        hero.summon("soldier");
    }
}

// Define the function: commandSoldiers
function commandSoldiers() {
    friends = hero.findFriends();
    for (var i = 0; i < friends.length ; i++) {
        var enemy = friends[i].findNearestEnemy();
        if (enemy) {
            hero.command(friends[i], "attack", enemy);
        }
    }
}
// Define the function: pickUpNearestCoin
function pickUpNearestCoin() {
    
}

var peasant = hero.findByType("peasant")[0];
var friends = hero.findFriends();
while(true) {
    summonSoldiers();
    // commandSoldiers();
    commandSoldiers();
    // pickUpNearestCoin();
    pickUpNearestCoin();
    
}


#2

2 questions 1 which area and 2 wich kind of code you using


#3

2 comments 1 just use direct link 2 the kind of code is obvious based on its structure


#4

so its python? or java


#5

Javascript (20000000000000000 chars)


#6

You need to fill in the function picknearestCoin();, the reason you are getting the error is because you are calling an empty function


#7

CloudRip Mountain Javascript


#8

I tried commenting out the code but the problem persists

// If the peasant is damaged, the flowers will shrink!

function summonSoldiers() {
    friends = hero.findFriends();
    if (hero.gold >= hero.costOf("soldier")) {
        hero.summon("soldier");
    }
}

// Define the function: commandSoldiers
function commandSoldiers() {
    friends = hero.findFriends();
    for (var i = 0; i < friends.length ; i++) {
        var enemy = friends[i].findNearestEnemy();
        if (enemy) {
            hero.command(friends[i], "attack", enemy);
        }
    }
}
// Define the function: pickUpNearestCoin
//function pickUpNearestCoin() {
//    
//}

var peasant = hero.findByType("peasant")[0];
var friends = hero.findFriends();
while(true) {
    summonSoldiers();
    // commandSoldiers();
    commandSoldiers();
    // pickUpNearestCoin();
    //pickUpNearestCoin();
    
}

#9

Hi @Christian_K, your problem’s in this function:

You’ve called the function “commandSoldiers”, but who are you really commanding?
Think who the function: hero.findFriends(); will return. Read the description of your Boss Star to see who it can summon / command.
After you’ve fixed that you just need to write your pickUpNearestCoin() function and you’re done. (I’ve checked you’re code and there aren’t any other errors.)
:lion: :lion: :lion:


#10

thanks that fixed the problem for me