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

Desert Combat - What am I missing?


I ended up just letting my troops do most of the fighting when my health got too low … worked ok after getting better armor

1 Like

I have no idea what to do why my hero doesn’t attack.
Can someone please point out what’s wrong with my code?

    if ordersGiven >= 5:
        self.moveXY(52, 29)
    if enemy:

Look at the previous post in this thread

note : you have used if instead if while , you haven’t told your friends to attack

1 Like

What you should do is put findNearestEnemy() at the start of your loop (but not in it!)
That way you can find the enemy.


Well, I decided to find another solution to the problem.

Create fire-traps.

1 Like
Desert combat - What am I missing?:

Hi Reznik,
there are a few points in your code which might not behave as you want.

First, you never actually give any orders. As a worthy commander, stand in front of each Soldier (that is on the cross) and self.say("Attack").
When you gave each soldier it’s order, self.findNearestEnemy() and self.attack(enemy) until all are dead.

The easiest way to solve this is to use while for the command-part and loop for the attack-part.

That might work as well, but was not the intention of the level.

1 Like

A general orders attacks from in front of his or her soldiers :wink:

General Dwight D. Eisenhower has been quoted as using a piece of string as a metaphor for leadership. He stated, "Leadership is like a piece of string. You will not succeed by pushing it, but only by pulling it along. … leading from in front :wink:


I have same problem.
To move on X I use Flags and then say to make soldiers to attack.
But If I am not quick enough to put next flag, my hero goes to attack like if while ordersGiven < 5 is true.

Here is the code.
Where I am wrong?
Thanks for help in advance!

ordersGiven = 0
while ordersGiven < 5:
    # Move and order each of your allies into battle.
    flag = self.findFlag("green")
    if flag:
    ordersGiven = ordersGiven + 1
# When you're done giving orders, join the attack.
    enemy = self.findNearestEnemy()


Rather than using flags to move, tell him to move as part of your loop. You can simply move 10 units down each time through the loop.


this is my code:

# We are field testing a new battle unit: the decoy.
# Build 4 decoys, then report the total to Naria.
# Each decoy costs 25 gold. Use the Quartz Sense Stone
# to know when you have more than 25 gold with
# Keep a count of decoys you built as you go along.
# Break out of the loop when you have built 4.
decoysBuilt = 0
    item = self.findNearestItem()
    self.moveXY(item.pos.x, item.pos.y)
    if >= 25:
        self.buildXY("decoy", 47, 43)
        decoysBuilt = decoysBuilt +1
    if decoysBuilt == 4:
        break  #中断语句
self.say("Done building decoys!")
# Go to Naria and say how many decoys you built.
self.moveXY(15, 36)

as long you are set up the enemy = self.findNerestEnemy() is inside the loop not outside the loop it will not find the enemy or wont attack at all.

for example look good

loop {
enemy = self.findNerestEnemy()
// the code here

other example wont attack

enemy = self.findNerestIEnemy()
loop {
// the code here


use this

ordersGiven = 0

while ordersGiven < 5:
    # 移動與命令同伴加入戰鬥 (你必須要站在士兵面前,他們才會聽到你的鼓舞)
    self.moveXY(self.pos.x, self.pos.y-9)
    ordersGiven = ordersGiven+1
self.moveXY(47, 32)
    enemy = self.findNearestEnemy()
    if enemy:

this doesnt work (if it did it doesnt now