I don’t know what to do I tried to do it on my own and I cant figure out the “palaside” part of the code
// Practice using modulo to loop over an array
// Choose the mix and order of units you want to summon by populating this array:
var summonTypes = ["soldier", "soldier","archer"];
function summonTroops() {
// Use % to wrap around the summonTypes array based on hero.built.length
//var type = summonTypes[???];
var type = summonTypes[hero.built.length % hero.summonTypes.length];
if (hero.gold >= hero.summon(type)) {
hero.summon(type);
}
}
function commandTroops(){
var friends = hero.findFriends();
var enemies = hero.findEnemies();
for (var i = 0, i<friends.length, i++){
var friend = friends[i];
var enemy = hero.findNearest(enemies);
if (friend.type == "palisade") {
if (enemy) {
hero.command(friend, "attack", enemy);
}
}
}
}
function pickUpCoins(){
var coins = hero.findItems();
var coin = hero.findNearest(coins);
if (coin) {
hero.move(coin.pos);
}
}
while(true) {
summonTroops();
commandTroops();
pickUpCoins();
}
what do you mean. It says in the hints that I should have type == “palisade”
so I made a few changes to my code and now when i run it, the soldiers will attack but my hero wont pick up coins until the enemies are attacking me.
// Practice using modulo to loop over an array
// Choose the mix and order of units you want to summon by populating this array{
var summonTypes = ["soldier", "soldier","archer"];
function summonTroops() {
// Use % to wrap around the summonTypes array based on hero.built.length
//var type = summonTypes[???];
var type = summonTypes[hero.built.length % summonTypes.length];
if (hero.gold > hero.summon(type)) {
hero.summon(type);
}
}
function commandTroops(){
var friend = hero.findNearest(hero.findFriends());
var enemy = hero.findNearest(hero.findEnemies());
if (enemy && friend.type != "palisade"){
if (friend){
hero.command(friend, "attack", enemy);
}
}
}
function pickUpCoin() {
// Collect coins
var items = hero.findItems();
var item = hero.findNearest(items);
if (item) {
hero.move(item.pos);
}
}
while(true) {
summonTroops();
commandTroops();
pickUpCoin();
}
Call the pickUpCoin();
function first
he still does the same thing
1 Like
I also have this problem if i put everything in functions. Paste the code for pickUpCoin();
in the while loop
he still wont move, he just stands there until the enemies get close
I think palisade hurts enemies on contact?
Self-contradiction oof
Haven’t been on CC for a long time