i Really cannot figure this one out i’ve been trying for about 20 days now
it keeps saying “empty elif statement put 4 spaces into the elif” Im not sure what i did wrong
any suggestions?
decoysBuilt = 0
hero.gold = 0
while True:
item = self.findNearestItem()
# Loot the coin!
x = item.pos.x
y = item.pos.y
hero.moveXY(x, y)
# Each decoy costs 25 gold. Use the Quartz Sense Stone
# to know when you have more than 25 gold with self.gold.
hero.gold += item.value
if hero.gold >=25:
hero.buildXY("decoy", hero.pos.x - 5,hero.pos.y)
# Keep a count of decoys you built as you go along.
decoysBuilt = decoysBuilt +1
# Break out of the loop when you have built 4.
elif decoysBuilt == 4:
First you need to replace the while true loop with a while loop. While decoysBuilt is less than four, you need to run the rest of the code. You need to indent all of this so that it is within the while loop, otherwise this piece of code will never run.
Before defining x and y as the item’s position x and y, you need to check if that item exists.
You can delete this statement.
You need to check if the decoysBuilt is equal to four. If it is equal to four, then break out of the loop using break.
You should indent the if-statement and what’s inside it because they are currently outside the while-true loop also you should add at the end inside the if-statement a “break” so that it exits the loop
decoysBuilt = 0
while True:
item = hero.findNearestItem()
# Loot the coin!
x = item.pos.x
y = item.pos.y
hero.moveXY(x, y)
# Each decoy costs 25 gold. Use the Quartz Sense Stone
# to know when you have more than 25 gold with self.gold.
hero.gold += item.value
if hero.gold >=25:
hero.buildXY("decoy", hero.pos.x - 5,hero.pos.y)
# Keep a count of decoys you built as you go along.
decoysBuilt +1
# Break out of the loop when you have built 4.
break
decoysBuilt = 0
while True:
item = hero.findNearestItem()
# Loot the coin!
x = item.pos.x
y = item.pos.y
hero.moveXY(x, y)
# Each decoy costs 25 gold. Use the Quartz Sense Stone
# to know when you have more than 25 gold with self.gold.
hero.gold += item.value
if hero.gold >=25:
hero.buildXY("decoy", hero.pos.x - 5,hero.pos.y)
# Keep a count of decoys you built as you go along.
decoysBuilt +1
# Break out of the loop when you have built 4.
break
sorry for making this a hassle to have this stuff explained to me i am quite dumb sometimes haha