# Desert Combat (SOLVED)

Hi, i’ve been stuck on Desert Combat for a while and was wondering if you could help me. I’m not sure if i just don’t have the methods our something is wrong with my code can you help me.

Heres my code:

``````# while-loops repeat until the condition is false.

ordersGiven = 0
while ordersGiven < 5:
# Move down 10 meters.
pet.moveXY(10, 50)
# Order your ally to "Attack!" with hero.say
# They can only hear you if you are on the X.
hero.say("Attack!")

# Be sure to increment ordersGiven!
ordersGiven:

while True:
enemy = hero.findNearestEnemy()
# When you're done giving orders, join the attack.
else:
hero.attack(enemy)

``````

Hey there!

Alright so I think because you are telling your pet to move not hero. Your XY has a hard factor and you are not telling it to subtract (move down) from the y axis while maintaining your x axis. It is in a true loop so it will keep repeating the move down until the conditions are met ending the while loop.

Also you are not adding to the orders given, it is just left blank. You need to tell the console to add 1 for every loop complete. (check hint section for further details on how to do this in your language)

So by telling your hero to move down 10m and say attack, then adding 1 to your loop, the condition “ordersGiven < 5” will automatically break out of the loop when you hit 5 and continue into your next while true loop.

The first loop “orderGiven < 5” is what it will continue to loop until conditions are met, and then continue onto the next section of your code.

Sorry if I explained this oddly at all. So without giving the answer here is what I do in JavaScript to move down x amount of meters. “hero.moveXY(hero.pos.x, hero.pos,y -10);” so my hero is staying on the same x axis (left to right) and moving down the y axis (up and down).

(I edited this comment a few times so that I gave info without full on giving the answer, I hope this helps!)

Also happy birthday=)

1 Like

Hi, thank you for the wishes. I was about to fix my code then I went on and now all my progress is gone and i’m all the way in the beginning. I’m wondering if you are able to fix this bug if now I can summon someone else.

Sorry, who are you trying to summon? I think that would be something you need to contact the dev’s about. As far as I know if you are a registered user all your old solutions save. (like if I go back in levels, all my old code is there)

1 Like

Yes, except when I logged in it says i’m on Kithgard Dungeun, but i’m actually on Sarven Desert, and if I try to go to where i’m at it won’t let me because it’s locked.

Are you automatically logging onto another account? Is your username, gems, achievements, etc… all the same? I know if I log on a different Facebook/google or am using a different computer and go to automatically log on Codecombat I have to make sure it is specifically selecting my account (sometimes even manually type in my credentials depending the pc)

1 Like

I think this is something @maka can help with.

1 Like

Hi.
Either DM me with your username or email team@codecombat.com for assistance (include your username). Also, make sure you’re logged in as the right user – go to https://codecombat.com/account/settings to check.

Maka

2 Likes

Hi, i’m SO sorry! I had made an account earlier and then made a second one later. I logged in my old account and thought it was my main account. Again I’m so sorry, I feel horrible!

1 Like

Hey, we’re all human, we all make mistakes =) I wouldn’t stress lol

2 Likes

I think a computer made a mistake which made somebody get fired before.

Hi, Areau I forgot to tell you thank you! I passed the level! Thank you again!

1 Like

Any time Naimaa1! I’m just happy I’ve learned enough that I can pass on the knowledge haha =)

2 Likes

No worries! These things happen (pretty often – which is why I was able to guess it might be the wrong account). Glad it’s resolved.

3 Likes

Hi, I need help with my code Plz help me. I honestly don’t know what to do. Plz, help me improve my skills! Thanks!

``````ordersGiven = 0

while ordersGiven < 5:
x = self.pos.x
y = self.pos.y - 10
self.moveXY(x, y)
self.say("Attack")
ordersGiven = ordersGiven+1.

while ordersGiven>=5:
ogre = hero.findNearestEnemy()
while True:
enemy = hero.findNearestEnemy()
enemy == "ogre"
if ogre:
hero.attack(ogre)
hero.cleave(ogre)
if enemy:
hero.attack(enemy)
hero.cleave(enemy)

``````

Here is the post:

ogre is brawler, not palisade. you’re attacking the fence

thanks I fixed that, but the brawler is dead and the hero is dead so i lost still

nevermind I got it (20 characters)

ordersGiven = 0
while ordersGiven < 5:
# Move down 10 meters.
x = self.pos.x
y = self.pos.y - 10
hero.moveXY(x, y)
# Order your ally to “Attack!” with hero.say
# They can only hear you if you are on the X.
hero.say(“Attack!”)

``````# Be sure to increment ordersGiven!
ordersGiven += 1
``````

while True:
enemy = hero.findNearestEnemy()
# When you’re done giving orders, join the attack.
if enemy:
hero.attack(enemy)