Kelvintaph Burgler helppp[SOLVED]

keep getting error "Try hero.pos"

def griffAtk(griff):
    enemies = hero.findByType("robot-walker")
    if len(enemies):
        hero.command(griff, "move", {'x': enemies[0].pos.x / 2 + enemies[1].pos.x / 2, 'y': enemies[0].pos.y / 2 + enemies[1].pos.y / 2})

Maybe make something like: x = enemies[0].pos.x / 2 + enemies[1].pos.x / 2
and y = enemies[0].pos.y / 2 + enemies[1].pos.y / 2.
After that, make this line:

{'x': x, 'y': y})
1 Like

still get error "Try hero.pos at x = enemies[0].pos.x / 2 + enemies[1].pos.x / 2

1 Like

Please post your code.

1 Like

It is possible that enemies don’t have property pos

1 Like

here full code

def griffAtk(griff):
    enemies = hero.findByType("robot-walker")
    x = enemies[0].pos.x / 2 + enemies[1].pos.x / 2
    y = enemies[0].pos.y / 2 + enemies[1].pos.y / 2
    if len(enemies):
        hero.command(griff, "move", {'x': x, 'y': y})
1 Like

You are calling griffAtk() inside the while true loop and when one of the robots is dead you
get this error.
The most simple way - call the function outside the while true loop :

hero.summon("griffin-rider")
hero.moveXY(14, 20)
griffAtk(hero.built[0])

and inside the loop but make sure it’s called only once:

doNothing = False

def griffAtk(griff):
    if doNothing:
        return
    global doNothing
    doNothing = True
    enemies = hero.findByType("robot-walker")
    x = (enemies[0].pos.x + enemies[1].pos.x) / 2
    y = (enemies[0].pos.y + enemies[1].pos.y) / 2
    hero.command(griff, "move", {'x': x, 'y': y})

hero.summon("griffin-rider")
pos = Vector(14, 20)

while True:
    if hero.distanceTo(pos) > 0:
        hero.move(pos)
    griffAtk(hero.built[0]);

Please don’t make the topic solved, I have something not absolutely clear, but I have no
time to ask for help now.

1 Like

Maybe you should make if len(enemies) if enemies[1]

i finnaly not gettin any error but my hero not commanding the soldier, archer, paladin

do i have to change this?

def command():
    for unit in hero.findFriends():
        t = unit.type
        if t == 'griffin-rider':
            griffAtk(unit)
        elif t == 'soldier':
            soldierAtk(unit)
        elif t == 'paladin':
            palaAtk(unit)
        elif t == 'archer':
            archerAtk(unit)

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