Level: Forest Fire Dancing

Hello all,

I’m a little stuck on this level and seeking some help. This is my code with comments cut out:

while True:

evilstone = hero.findNearestItem()
if evilstone:
pos = evilstone.pos
if pos.x == 34:
hero.moveXY(46,22)

else:
hero.moveXY(34,22)

else:
hero.moveXY(40,22)

For some reason my character just stops after about 11 seconds and stands in the middle, getting hit with a fireball. Everything is running great up to that point.

I also tried changing the nested else statement to an elif pos.x == 46 but this did not help.

Any help would be greatly appreciated.

1 Like

I fixed it. Disregard.

1 Like

I also have a similar problem, my hero would be dodging the fireballs and then after he dodges one certain fireball, the fireballs would stop, then, my hero would die. Here is my code:

while True:
    evilstone = hero.findNearestItem()
    if evilstone:
        pos = evilstone.pos
        if pos.x == 34:  
            hero.moveXY(46, 22)
            
            pass
        else:
            hero.moveXY(34, 23)
            pass
    else:
        hero.moveXY(40, 22)
        pass

1 Like

I can’t find a problem or anything wrong with my code.

Change 23 to 22 and you’ll win

while True:
evilstone = hero.findNearestItem()
if evilstone:
pos = evilstone.pos
if pos.x == 34: # == means “is equal to”
# If the evilstone is on the left, go to the right side.
hero.moveXY(46, 22)
pass
else:
# If the evilstone is on the right, go to the left side.
hero.moveXY(34, 23)
pass
else:
# If there’s no evilstone, go to the middle.
hero.moveXY(40, 23)
pass

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    else:
        hero.say("My code is formatted properly")

If ALL of your code isn’t formatted like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well.

Thank you.

Mod edit: [Please don’t post successful solutions.]

Hi @House and welcome to the forum! :partying_face:

What do you mean by that? And please mind your language, because idiot is a word that can make the person sad.

Andrei

2 Likes

This is my code it my hero keeps on dying in the middle can you help me
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)
hero.moveXY(40, 22)
hero.moveXY(46, 22)
hero.moveXY(40, 22)
hero.moveXY(34, 22)

could you please format your code properly by clicking this button and then image pasting it inside

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

@Joshua_Lange you should be using if loops and while loops and you are not doing the level the correct way. Use the hints as they will help a little bit