Haris
October 22, 2021, 9:25am
1
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})
Rabbit
October 22, 2021, 9:48am
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
Haris
October 22, 2021, 10:13am
3
still get error "Try hero.pos
at x = enemies[0].pos.x / 2 + enemies[1].pos.x / 2
1 Like
Aya
October 22, 2021, 11:32am
5
It is possible that enemies don’t have property pos
1 Like
Haris
October 22, 2021, 11:49am
6
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
Rabbit
October 22, 2021, 11:12pm
8
Maybe you should make if len(enemies)
if enemies[1]
Haris
October 23, 2021, 7:20am
9
i finnaly not gettin any error but my hero not commanding the soldier, archer, paladin
Haris
October 23, 2021, 7:26am
10
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)
system
Closed
October 24, 2021, 9:02am
11
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.