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

Combo Challenge: Forest storm

I need help with the combo challenge “forest storm” in cs3. plz help
here is my current code:
// Attack enemies or collect items less than 15 meters away.
// Collect only “coin” type items.
// Attack only “munchkin” type enemies.

function collectAndAttack {
var coin = hero.findNearestItem();
if(item){
if (item.type == “coin”) {
hero.moveXY(item.pos.x, item.pos.y);
}
}
hero.moveXY(40, 34);
var enemy = hero.findNearestEnemy();
if (enemy) {
if (enemy.type == “munchkin”) {
hero.attack(enemy);
}
}
hero.moveXY(40, 34);

}

while(true) {
collectAndAttack;
}

Hi @Caleb_Stafford welcome to the CodeCombat discourse.
I presume you’re being killed by the lightning? I can’t actually test it unfortunately because when I try to change the programming language it automatically reloads the level.
But what I see from looking at your code is that you’re going for items and enemies that are further than 15m from you, then moving back to the middle. Why don’t you only go for items and enemies within 15m, then you won’t get hit by lightning and you won’t need to move back to 40, 34.