Stillness in Motion Python


#1
loop:
    enemy = self.findNearestEnemy()
    if enemy:
        self.distanceTo(enemy) < 5
        self.attack(enemy)
    if enemy:
        self.distanceTo(enemy) > 5
        self.shield()
    else:
        self.moveXY(40, 34)

Hi.
This is my code for Stillness in motion. I have no clue what is wrong but it’s not working. Sorry if it’s not formatted right but I’m short on time and am in ICT class at school. If someone could lend a hand that’d be great.


#2

The FAQ specifically says “Read Before Posting”. If you didn’t read the FAQ, then you shouldn’t be posting. I will do it for you this time, but don’t post again until you have read the FAQ.

I’ll go through your code line by line:

Line 4: self..distanceTo(enemy) < something returns a boolean that states whether it is true or not. This should be an if-statement.

Line 7: See line 4.


#3

What do you mean by it should be an if-statement. I have if enemy: as my if, but I end up walking over to the head hunters instead.


#4

@ChronistGilver means instead of:

if enemy:
self.distanceTo(enemy) < 5:

It would turn into:

if enemy and self.distanceTo(enemy) < 5:

#5

I finally got it. Thank you so very much.