# How do I find the middle of the two robots?

What I’m trying to do with kelvintaph burgler Is get between the 2 robots and make them kill each other.

# What eldritch artifacts are these? Don't let them blast you!
# The ice gate will open when both ogres die.
loop:
enemies = self.findEnemies()
if enemies.type == 'robot-walker':
for robotWalkers in enemies:
a = enemies[0]
b = enemies[1]
vector = Vector.subtract(a.pos,b.pos) #error says 'Try self.pos'
moveToPosTimes2 = Vector.normalize(vector)
moveToPos = Vector.divide(moveToPosTimes2, 2)
self.move(moveToPos)
self.say("Hit me with your best shot!")
self.move(65,15)

For finding the middle of the two positions it’s easier to keep it simple and use the midpoint formula.

Midpoint Formula

As for using Vectors, don’t normalize the Vector, because then you will mess up the vector’s magnitude. You’ll also need to add the vector to the vector you subtracted by, or else your hero will be traveling relative to (0, 0).

Some other problems:

• enemies is a Array/List, so it has no type, so the if block isn’t running (and as such a and b are undefined)
• move() moves incrementally, so in the loop you’ll be moving, then say(), then move, then say() then move, etc.

Yet another problem: the list returned by self.findEnemies() does not contain any robot-walker (at least in my tests). I couldn’t think of any easy way to reference them.

Also, whats wrong with this?

Fp = friend.pos
while Fp.x <= 50:
self.command(friend, "move", {'x':50,'y':59})
while Fp.y >=44:
self.command(friend, "move", {'x':40,'y':44})

@trotod It says that there is an infinite loop.

@UltCombo Seems like the robots spawn after the first frame, which makes them visible to the hero then but not before. (A weird workaround without using wait(some small dt) is to use say(""), which only takes one frame, rather than 3 seconds, to complete.)

@Xiaoying_Qin Parser “breaks” when using loops like that, you could either use the say("") trick in those loops to make the hero “do something” so that there won’t be an infinite loop, or rewrite the logic so it’s something like

loop:
if friend.pos.x <= 50:
self.command(...)
elif friend.pos.y >= 44:
self.command(...)

# other code

(Though one problem at a time: I’m assuming you’ve fixed your original problem with finding the midpoint.)

2 Likes

Nice! I didn’t even think that they would spawn after the first frame.

@trotod i gave up on the midpoint thing. Can’t figure out what is wrong NOW.

goalPoint = Vector(61, 14)
friends = self.findFriends()
witch = self.findByType("witch")
ogre = self.findByType("ogre")
yak = self.findByType("ice-yak")
loop:
goal = Vector.subtract(goalPoint, self.pos)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, 10)
beam = self.findNearest(self.findEnemyMissiles())
if beam:
distance = self.distanceTo(beam)
else:
distance = None
if distance < 10 and distance:
bvector = Vector.subtract(self.pos, beam.pos)
bvector = Vector.normalize(bvector)
bvector = Vector.multiply(bvector, 10)
pass
self.move(moveToPos)
if self.pos.x >= 59:
self.moveXY(25,16)
if friends:
for friend in friends:
Fp = friend.pos
if Fp.x <= 52:
self.command(friend, "move", {'x':52,'y':58})
elif Fp.x >=40:
self.command(friend, "move", {'x':40,'y':44})
if ogre.health<=0:
self.command(friend, "attack", witch)

@trotod Are you able to help me now? I am using flags and they work, but the people always target the yak after the witch. I can’t seem to cast chain-lightning either, can you help me with that?

My strategy: get paladin to visible sight of ogre chieftan
get him to the yak
get everyone piled up at the witch
attack witch
scape

# What eldritch artifacts are these? Don't let them blast you!
# The ice gate will open when both ogres die.
goalPoint = Vector(61, 14)
friends = self.findFriends()
witch = self.findByType("witch")
ogre = self.findByType("ogre")
yak = self.findByType("ice-yak")
stuff = False
goalPoint = Vector(61, 14)
enemyKilled=0
loop:
blackFlag = self.findFlag("black")
greenFlag = self.findFlag("green")
violetFlag = self.findFlag("violet")
goal = Vector.subtract(goalPoint, self.pos)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, 10)
beam = self.findNearest(self.findEnemyMissiles())
if beam:
distance = self.distanceTo(beam)
else:
distance = None
if distance < 10 and distance:
bvector = Vector.subtract(self.pos, beam.pos)
bvector = Vector.normalize(bvector)
bvector = Vector.multiply(bvector, 10)
pass
self.move(moveToPos)
if self.pos.x >= 59:
goalPoint = Vector(25, 16)
if self.pos.x <= 27:
goalPoint = Vector(61, 16)
if violetFlag:
goalPoint = Vector(76, 16)
if friends:
for friend in friends:
blackFlag = self.findFlag("black")
greenFlag = self.findFlag("green")
violetFlag = self.findFlag("violet")