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

[SOLVED] CodeCombat Sarven Gaps (Help Needed)

Sorry if this is not clear, I’m new to this discourse.

My problem is that whenever I move, I move TOWARDS the enemy. I know which code did it but I’m really bad at moveXY in the desert. So please help.

// Get to the Oasis by moving down 10m at a time.
// Build fences 20m to the left of each ogre.

while(true) {
    var enemy = hero.findNearestEnemy();
    var x = hero.pos.x;
    var y = hero.pos.y;
    
    if (enemy) {
        // buildXY a "fence" 20 meters to enemy's left.
        x = x + 20;
        hero.buildXY("fence", enemy.pos.x,enemy.pos.y);
    } else {
        // moveXY down 10 meters.
        y = y- 10;
        hero.moveXY(x, y);
    }
}

Nevermind, I solved it no help needed anymore.

here are my mistakes. I deleted most of the code so people can’t copy it.

    var xPos = hero.pos.x;
    var yPos = hero.pos.y;

        var x = enemy.pos.x;
        var y = enemy.pos.y;

        x = x - 20;
        hero.buildXY("fence", x, y);

Welcome to discourse athian, and well done for solving your own problem :smile:

No worries I bet most of us is already finished the game, but good job, congrats, YAY

Thanks guys!! It means alot to me

YAY(20 characters needed)

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.