Can't figure out capture their flag

I don’t have any code I want to develop a strategy as I go. I don’t know who the level really works. I tried to do basic code like this.

while True:
    friends = hero.findFriends()
    friend = hero.findNearest(friends)
    flag = hero.findEnemyFlags()
    enemies = hero.findEnemyFlags()
    nearest = hero.findNearest(enemies)
    if nearest:
        if hero.distanceTo(nearest) <= 3:
            hero.moveXY(43, 60)
    if flag:

I don’t understand why it does not work.

Your hero can only find flags when your hero is a certain distance from them. Then, your hero can only pick them up if they are even closer.

What is that range exactly. Whenever my hero moves he slides and ends up somewhere else.

I got the distance part set for how to capture it read this

So I moved to the middle but still I don’t do anything. Also how do you command your robo-walker.

Move close to the flags:
Screenshot 2021-01-23 at 5.22.19 PM
find the enemy flags, then bring them back.

so retrun nearest do that