The Trials - Python Help

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})

plz format

self.say("plz format")

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})

Thats what I needed. Thank you!

How do I indent my code?

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

your_Code

1 Like

can you please give me some help i don’t have any code

please please please!!!

Calm down. Saying please three times isn’t going to help.
Try and write some code, you could use flags, hero.time, hero.moveXY(), special abilities, etc…
This is an optional challenge level, so it’s quite hard. You’ll have to put a bit more effort in before I give you proper help.
Danny

did I make a mistake in this if so can you please help me

enemy = hero.findNearestEnemy()
enemyMissiles = hero.findEnemyMissiles()
hazards = hero.findHazards()
hero.findNearest(hero.findEnemies())
enemies = hero.findEnemies()
for enemy in enemies:
    while True:
        if enemy:
            if enemy.type != "sand-yak":
                hero.attack(enemy)
            if hazards or enemyMissiles:
                hero.shield()
            if hero.health < 400:
                # Health is low–retreat!
                while True:
                    hero.shield()
            else:
                # Health is fine. Fight!
                hero.attack(enemy)

I really need help so can you please help me

Do we learn “for” in Desert? Is it your code?

for loops is officially covered in the mountains, not the desert. (Programmaticon IV)

Yes. So that’s why I ask wazi about code.

Since The Trials is an optional subscriber challenge level, he might’ve learned for loops already.

Okay.
So let’s help wazi.

1 Like

In this level I used flags and collected mushrooms (items).
Also, try to put al these things:

to the While True loop.

1 Like

Why do you need this if you already have

.

I do not think that you will need those in this level.

All the variables you need for this level is:

enemy = hero.findNearestEnemy()
flag = hero.findFlag("black")
item = hero.findNearestItem()

The flag and item are optional, but you’ll need moveXY if you don’t use the flag. I find the flag helpful in this level.
I completed the level with Naria. This is a level where you’ll need good strategy or good armor.
Please send a screenshot of your armor.
Thanks, Lydia

1 Like

sorry about the

enemy = hero.findNearestEnemy()

and the

enemies = hero.findEnemies()

I’ll fix my code

There it goes

enemy = hero.findNearestEnemy()
enemyMissiles = hero.findEnemyMissiles()
hazards = hero.findHazards()
hero.findNearest(hero.findEnemies())
item = hero.findNearestItem()
for enemy in enemies:
    while True:
        if enemy:
            if enemy.type != "sand-yak":
                hero.attack(enemy)
            if hazards or enemyMissiles:
                hero.shield()
            if hero.health < 400:
                # Health is low–retreat!
                while True:
                    hero.shield()
            else:
                # Health is fine. Fight!
                hero.attack(enemy)