I ended up just letting my troops do most of the fighting when my health got too low … worked ok after getting better armor
I have no idea what to do why my hero doesn’t attack.
Can someone please point out what’s wrong with my code?
loop: if ordersGiven >= 5: self.moveXY(52, 29) if enemy: self.attack(enemy) else: self.isReady("cleave") self.cleave(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
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.
Desert combat - What am I missing?:
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
When you gave each soldier it’s order,
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.
A general orders attacks from in front of his or her soldiers
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
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: self.pickUpFlag(flag) self.say("Attack!") ordersGiven = ordersGiven + 1 # When you're done giving orders, join the attack. loop: enemy = self.findNearestEnemy() self.attack(enemy)
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 self.gold. # Keep a count of decoys you built as you go along. # Break out of the loop when you have built 4. decoysBuilt = 0 loop: item = self.findNearestItem() self.moveXY(item.pos.x, item.pos.y) if self.gold >= 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) self.say(decoysBuilt)
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
enemy = self.findNerestEnemy()
// the code here
other example wont attack
enemy = self.findNerestIEnemy()
// the code here
ordersGiven = 0 while ordersGiven < 5: # 移動與命令同伴加入戰鬥 (你必須要站在士兵面前，他們才會聽到你的鼓舞) self.moveXY(self.pos.x, self.pos.y-9) self.say("Attack!") ordersGiven = ordersGiven+1 self.moveXY(47, 32) loop: enemy = self.findNearestEnemy() if enemy: self.attack(enemy)
this doesnt work (if it did it doesnt now