The Trials - Python Help


#1

I have been trying to solve The Trials in parts. This is my code for getting to the first oasis. It was working but now it is giving me the error that “distanceTo target is null”. Any help with how to solve this would be great.
loop: enemies = self.findEnemies() nearest = self.findNearest(enemies) distance = self.distanceTo(nearest) if distance: if distance <= 25: self.attack(nearest) else: self.move({"x": 135, "y": 15})


#2

plz format

self.say("plz format")


#4

Most of the functions will give generate an error if you do not give them a valid argument.
The error:
"distanceTo target is null"
says that the value nearest used to call:

distance = self.distanceTo(nearest)

is null.

This will happen if there are no enemies near your hero.

Do a test beforehand to make sure you have an nearest enemy.
I actually like that you were checking iif the distance is valid, but the error was occurring before that

loop:
    enemies = self.findEnemies()
    nearest = self.findNearest(enemies)
    if (nearest)
        distance = self.distanceTo(nearest)
            if distance <= 25:
                self.attack(nearest)
            else:
                self.move({"x": 135, "y": 15})

#5

Thats what I needed. Thank you!


#6

How do I indent my code?


#7

put 3 backquotes (left-top symbol on your keyboard on a empty line before and after your code)

your_Code