That’s what I tried, and it never stops.
Here’s my code.
We are field testing a new battle unit: the decoy.
Build 4 decoys, then report the total to Naria.
decoysBuilt = 0
loop:
item = self.findNearestItem()
if item:
pos = item.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
pass
# Each decoy costs 25 gold.
# Know when you have more than 25 gold with self.gold
if self.gold >= 25:
newX = self.pos.x - 5
newY = self.pos.y
self.buildXY(“decoy”, newX, newY)
# Keep a count of decoys you built as you go along.
if decoysBuilt == 4:
# Break out of the loop when you have built 4.
break
pass
self.say(“Done building decoys!”)
self.moveXY(14, 36)
You need to iterate decoysBuilt, either with decoysBuilt = decoysBuilt + 1 or decoysBuilt += 1. I will leave it to you to figure out where it goes.
Also, I see you only joined three days ago. Before you post again you should probably read the FAQ and learn how to properly post your code. I’m sure someone will come along and fix it this time, but you should know it for the future.
Here’s the FAQ. You can also find it by opening the “hamburger” menu (the icon that has three horizontal lines near the top-right of the screen) and clicking “FAQ”.
I have a problem. Every time I try, it doesn’t stop. This is my code:
decoysBuilt = 0
while True:
coin = hero.findNearestItem()
if coin:
# Collect the coin!
hero.moveXY(coin.pos.x, coin.pos.y);
pass
# Each decoy costs 25 gold.
# If hero.gold is greater than or equal to 25:
if hero.gold >= 25:
# buildXY a "decoy"
hero.buildXY("decoy", 36, 30)
hero.wait(4)
# Add 1 to the decoysBuilt count.
decoysBuilt == decoysBuilt + 1
if decoysBuilt == 4:
# Break out of the loop when you have built 4.
break
pass
hero.say("Done building decoys!")
hero.moveXY(14, 36)
# Say how many decoys you built.
hero.say("I built 4 decoys")