[SOLVED] Multiplayer Treasure grove help

Whenever I try to attack the enemy it always says “Line 11: ArgumentError: distanceTo’s argument target should have type object, but got function. Find the distance to a target unit.” My code is below.

# Be the first to 100 gold!
# If you are defeated, you will respawn at 67% gold.
enemy = hero.findNearestEnemy
while True:
    #  Find coins and/or attack the enemy.
    # Use flags and your special moves to win!
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x,item.pos. y)
    if enemy:
        if hero.distanceTo(enemy) < 5:
            if hero.isReady("cleave"):
                hero.cleave(enemy)
            else:
                hero.attack(enemy)

Please help me with this issue.

Hi @GraySkayl007, Welcome to the Discourse :partying_face: :tada:
Notice how you made the mistake here, you should have brackets at the end.

Suggestion: Try to increase the distance of hero.distanceTo, or else you player is going to keep attacking the target if it’s 5 blocks away

1 Like

Hi @GraySkayl007 and welcome to the forum! :partying_face:

I knew that you find the enemy using the findNearestEnemy() method, isn’t it how you find it?

Andrei

1 Like

Thank you both for the help, but I still can’t beat the CPU with the code I currently have.

2 Likes

Nevermind, it worked. Thank you!

2 Likes

No problem! And congratulations! :partying_face:

Andrei

1 Like

One more question. Is it worth it to subscribe to CodeCombat?

1 Like

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