Error on Interception! Please help!


#1

I’m having trouble on Interception. Here’s my code:

def mid(a,b):
    newX = (a.pos.x + b.pos.x) / 2
    newY = (a.pos.y + b.pos.y) / 2
    pass
while True:
    enemy = hero.findNearestEnemy()
    friend = hero.findNearestFriend()
    hero.targetPos = mid(enemy,friend)
    hero.moveXY(hero.targetPos.x, hero.targetPos.y)
    pass

All it tells me is “TypeError: Cannot read property ‘realm’ of undefined” and then it highlights (a.pos.y + b.pos.y) in line 3.


#2

hero.targetPos = mid(enemy,friend) I dont know what your doing but this is not a valid statement.

Edit: This is not valid hero.targetPos =

hero.targetPos should not be before the = sign.

I guess I should explain that the (.) Is reserved for methods.


#3

I defined that function in the code.


#4

Sorry. I saved up my gems for the sapphire sense stone, which offers that function.


#5

Im not saying you cant use it. You just cant be using it before the = sign. Thats a method from the sapphire stone its not a variable to be holding a number.


#6

I just want to point out this does not work for 2 reasons. hero.targetPos = mid(enemy,friend)

hero.targetPos can not be assigned to hold a value.
mid(enemy,friend) This method is fine except that it doesnt return anything. It looks like you want use this return value as an object. You need to return an object holding the two new variables.

This can work if you replace the period with _ or nothing have the words touching. Then have your Mid function return an object.

Im just guessing but chances are your error is because your variables dont hold a value when passed. You should check to see if theirs an enemy and a friend before using your function.