The Trials - Python Help

There it is
FireShot Capture 060 - Play CodeCombat Levels - Learn Python, JavaScript, and HTML -CodeCom_ - codecombat.com324x433, 100%

Try to put al these things:

to the While True loop.

okay I’ve change my code

enemy = hero.findNearestEnemy()
if len(hero.findFriends()) > 5:
    hero.shield()
else:
    hero.attack(enemy)
if len(hero.findFriends()) > 5:
    hero.shield()
else:
    hero.attack(enemy)
66.67
enemy = hero.findNearestEnemy()
if enemy:
    # Use if to make sure enemy exists before checking its distance.
    distance = hero.distanceTo(enemy)
    if distance < 10:
        hero.attack(enemy)
    else:
        hero.say("Come closer!")
hero.findByType("thrower", hero.findFriends())
enemies = hero.findEnemies()
for enemy in enemies:
    # Do something with each enemy here
    hero.attack(enemy)  # Example
friends = hero.findFriends()
for friend in friends:
    # Do something with each friend here
    hero.follow(friend)
items = hero.findItems()
for item in items:
    # Do something with each item here
    hero.moveXY(item.pos.x, item.pos.y)
hero.findNearest(hero.findItems())
enemy = hero.findNearestEnemy()
hero.attack(enemy)
hero.attack(enemy)
item = hero.findNearestItem()
if item:
    # Move to the position of the item.
    pos = item.pos
    x = pos.x
    y = pos.y
    hero.moveXY(x, y)
item = hero.findNearest(hero.findItems())
if item and hero.isPathClear(hero.pos, hero.pos):
    hero.move(item.pos)
else:
    hero.move({"x": hero.pos.x, "y": hero.pos.y + 5})
if hero.health < 200:
    # Health is low–retreat!
    hero.moveXY(61, 46)
else:
    # Health is fine. Fight!
    hero.attack(enemy)
1521.30
if hero.health < hero.maxHealth / 3:
    # Health is low–retreat!
    hero.moveXY(61, 46)
else:
    # Health is fine. Fight!
    hero.attack(enemy)
5121.30
# Move 10 meters to the right.
ne.wX = hero.pos.x + 10
newY = hero.pos.y
moveXY(newX, newY)
{x: 23.59, y: 18.31,z: 1.00}
if hero.gold > 100:
    hero.say("I'm rich!")
null
if hero.isReady("cleave"):
    hero.cleave(enemy)
else:
    hero.attack(enemy)
if hero.time < 30:
    hero.say("Wait...")
hero.wait(0.1)
hero.moveXY(24, 35)
hero.canElectrocute(hero.findNearestEnemy())
hero.electrocute(hero.findNearestEnemy())
flag = hero.findFlag()
if flag:
    if flag.color is "black":
        hero.buildXY("fire-trap", flag.pos.x, flag.pos.y)
    hero.pickUpFlag(flag)
greenFlag = hero.findFlag("green")
if greenFlag:
    hero.pickUpFlag(greenFlag)
arr = ["this is the first element", "this is the second element"]
hero.say(arr[0])                # says "this is the first element"
hero.say(arr[1])                # says "this is the second element"
hero.say(arr[len(arr) - 1])     # says "this is the second element

arr[0] = 'new first element'
arr.append('a third element')   # append() adds an element at the end

lastElement = arr[-1]           # elements can be referenced from the end of the list using negative index values   
while True:
    enemy = hero.findNearest(hero.findEnemies())
    if not enemy:
        break
    hero.attack(enemy)
hero.say("/人 ◕ ‿‿ ◕ 人\")
if hero.isReady("cleave"):
    hero.cleave(enemy)
else:
    hero.attack(enemy)
# Example: if you see an enemy, then attack it.
enemy = hero.findNearestEnemy()
if enemy:
    hero.attack(enemy)

# More examples
enemy = hero.findNearestEnemy()
if not enemy:
    # If there is *not* an enemy, then move...
    hero.moveXY(30, 30)
elif enemy.type is "thrower":
    # ... else if the enemy's type *equals* "thrower", then attack...
    hero.attack(enemy)
elif hero.isReady("cleave") and hero.distanceTo(enemy) < 10:
    # ... else if "cleave" is ready *and* the distance is *less than* 10m, then cleave...
    hero.cleave(enemy)
else:
    # ... else, shield.
    hero.shield()
i = 10
while i >= 0:
    hero.say("Counted to " + i)
    i -= 1
# Example: looping through a maze.
while True:
    hero.moveRight()
    hero.moveDown()
    hero.moveRight()
    hero.moveUp()

# Example: attack an enemy over and over.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
hero.say("Hi!")

my hero keeps on saying “but it’s dead” and I have too less health
my health is only 1521

If you put else infront of if, the if won’t run at all.
Lydia

i need help in my code

If you need help then please post your code into the forum from the game, and paste it inbetween two lines of ``` because that will format the code.
Danny

3 Likes

Wazi, your code is fine but there is a big mistake,

Firstly, these and the for loop should be inside the while true loop.

Secondly,

Once you see a long-range enemy’s missile you will stop attacking and keep shielding but nobody is going to help you defeat the enemy.
Thirdly, you are not collecting mushrooms, btw mushrooms in this level can heal you.
Also you can try using flags.
Hope this helps. Oh, and are you a sub, wazi?

If you are a sub, you can gain access to 50000 gems at first to buy better armor as health is really important at this level.

Actually its 43 000
20 characters

My new account gained me 50000 gems though Eric_Tang so I believe it is 50000 gems.

Did you do some permanent spending or stuff?