[SOLVED] Help! Brewball Level

Hi guys, so I am stuck on brewball. I have got the first part right, catching a potion, but I am stuck on getting back to Omarn and I get this t.copy error:


Here is my code:

// Say anything within 10m of Omarn for him to throw a potion.
// Catch the potion by standing near it before it lands.
// DO NOT LET THE POTION LAND ON THE GROUND!

while(true) {
    var potion = hero.findFriendlyMissiles()[0];
    var firetraps = hero.findNearest(hero.findHazards());
    // Remember that a Fire Trap will trigger if you move closer than 3 meters!
    var omarn = hero.findByType("potion-master")[0];
    if(potion) {
        var dest = potion.targetPos;
        // Go get the potion.
        var potion = Vector.subtract(dest, hero.pos);
        potion = Vector.normalize(potion);
        potion = Vector.multiply(potion, 5);
        if (firetraps) {
            if (hero.distanceTo(firetraps) < 3) {
                var trapVector = Vector.subtract(hero.pos, firetraps.pos);
                trapVector = Vector.normalize(trapVector);
                trapVector = Vector.multiply(trapVector, 10);
                potion = Vector.add(trapVector, potion);
            }
        }
        // Warning: isPathClear doesn't work with Hazards!
        var moveToPos = Vector.add(hero.pos, potion);
        hero.move(moveToPos);
    } else {
        if(omarn && hero.distanceTo(omarn) > 10) {
            // Move back to Omarn.
            var home = {"x": 14, "y": 34};
            // Go back to the x.
            var xpos = Vector.subtract(home, hero.pos);
            xpos = Vector.normalize(xpos);
            xpos = Vector.multiply(xpos, 5);
            if (firetraps) {
                if (hero.distanceTo(firetraps) <= 3) {
                    trapVector = Vector.subtract(hero.pos, firetraps.pos);
                    trapVector = Vector.normalize(trapVector);
                    trapVector = Vector.multiply(trapVector, 5);
                    xpos = Vector.add(trapVector, xpos);
                }
            }
            // Warning: isPathClear doesn't work with Hazards!
            moveToPos = Vector.add(hero.pos, xpos);
            hero.move(moveToPos);
        } else {
            hero.say("Hup, hup!");
        }
    }
}

Thanks for any help!

Could you remove the comments from the code please? Because for some reason coco discourse always thinks the code is in Python

I don’t think that’s necessary

Please, could anyone help?

Its super hard to read when its red :confused:

# Say anything within 10m of Omarn for him to throw a potion.
# Catch the potion by standing near it before it lands.
# DO NOT LET THE POTION LAND ON THE GROUND!

while(true) {
    var potion = hero.findFriendlyMissiles()[0];
    var firetraps = hero.findNearest(hero.findHazards());
    # Remember that a Fire Trap will trigger if you move closer than 3 meters!
    var omarn = hero.findByType("potion-master")[0];
    if(potion) {
        var dest = potion.targetPos;
        # Go get the potion.
        var potion = Vector.subtract(dest, hero.pos);
        potion = Vector.normalize(potion);
        potion = Vector.multiply(potion, 5);
        if (firetraps) {
            if (hero.distanceTo(firetraps) < 3) {
                var trapVector = Vector.subtract(hero.pos, firetraps.pos);
                trapVector = Vector.normalize(trapVector);
                trapVector = Vector.multiply(trapVector, 10);
                potion = Vector.add(trapVector, potion);
            }
        }
        # Warning: isPathClear doesn't work with Hazards!
        var moveToPos = Vector.add(hero.pos, potion);
        hero.move(moveToPos);
    } else {
        if(omarn && hero.distanceTo(omarn) > 10) {
            # Move back to Omarn.
            var home = {"x": 14, "y": 34};
            # Go back to the x.
            var xpos = Vector.subtract(home, hero.pos);
            xpos = Vector.normalize(xpos);
            xpos = Vector.multiply(xpos, 5);
            if (firetraps) {
                if (hero.distanceTo(firetraps) <= 3) {
                    trapVector = Vector.subtract(hero.pos, firetraps.pos);
                    trapVector = Vector.normalize(trapVector);
                    trapVector = Vector.multiply(trapVector, 5);
                    xpos = Vector.add(trapVector, xpos);
                }
            }
            # Warning: isPathClear doesn't work with Hazards!
            moveToPos = Vector.add(hero.pos, xpos);
            hero.move(moveToPos);
        } else {
            hero.say("Hup, hup!");
        }
    }
}

Converted it into Python comments to make it readable.

List of errors:

  1. the objects you wrote are in Python syntax and not Javascript syntax (thats the error its giving you right now)
  2. you must define trapVector outside of the ifs for it to work everywhere in the while-loop
    and thats it. :slight_smile:
1 Like

Which objects? (20Chars)

this (20 charssssss)

Ah, thanks for the help @moonwatcher348!

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