Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Desert combat help : how to increment ordersGiven?

I am stuck in this level and I don’t know how to use the new /# Be sure to increment ordersGiven/.
I hope you can help me to get out of this level.

# while-loops repeat until the condition is false.
ordersGiven = 0
while ordersGiven < 5:
# Move down 10 meters.
ordersGiven += 1
# 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!

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

Welcome to the forum! Please format your code properly. You can learn how, here: [Essentials] How To Post/Format Your Code Correctly

That being said, to “increment” is to increase by 1 (or any value). Think of it as a counter. ‘ordersGiven’ is the counter in this case. Every time you give an order, you want to increase ‘ordersGiven’ by 1, or increment it…’+= 1’ is a method for doing this. Another method, which does exactly the same thing is:

ordersGiven = ordersGiven +1.

The ‘+= 1’ method is shorter (to type), but still does the adding of 1 to the counter.

1 Like

Ok, and thank you! I finished it by adding that block :slightly_smiling_face:

I will format my code next time! I forgot to press </> that time ( sorry :cry: ) Thanks for reminding me

And finally this problem is solved!