Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Https://codecombat.com/play/level/second-gem?


#1

Hello. help with the task “second gem” in the desert. it seems the code is correct. after the second cycle, the gems no longer come out.


#2
while True:
    items = hero.findItems()
    # Если длина массива больше или равна 2:
    gem2=items[1]
    if len(items)>=2:
        # Двигайся ко второму предмету массива.
        hero.moveXY(gem2.pos.x, gem2.pos.y)
    # Иначе:
    else:
        # Двигайся в центр.
        hero.moveXY(40, 33)

#3

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly


#4

here did … and what’s the difference? why the first code didn’t work?
Mod edit: Please do not post successful solutions.


#5

We do not post successful solutions on the board, as it interferes with learning. The difference between the first code and the second code is that in the first code you’re checking the second gem before the length of the gem is greater than or equal to 2. While in the second code, you are checking the second gem after the length of the gem is greater than or equal to 2.