Hello Guys,
Need your help in this, my hero never stops gathering coins and execute the next 2 functions:
Code:
// This level shows how to define your own functions.
// The code inside a function is not executed immediately. It's saved for later.
// This function has your hero collect the nearest coin.
this.pickUpNearestCoin = function() {
var items = this.findItems();
var nearestCoin = this.findNearest(items);
if(nearestCoin) {
this.move(nearestCoin.pos);
}
};
// This function has your hero summon a soldier.
this.summonSoldier = function() {
// Fill in code here to summon a soldier if you have enough gold.
if ( this.gold < this.costOf("soldier") ) {
this.summon("soldier");
}
};
// This function commands your soldiers to attack their nearest enemy.
this.commandSoldiers = function() {
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var enemy = friends[i].findNearestEnemy();
if(enemy) {
this.command(friends[i],"attack", enemy);
}
}
};
loop {
// In your loop, you can "call" the functions defined above.
// The following line causes the code inside the "pickUpNearestCoin" function to be executed.
this.pickUpNearestCoin();
// Call summonSoldier here
this.summonSoldier();
// Call commandSoldiers here
this.commandSoldiers();
}
please help