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

[SOLVED] Decoy Drill

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:
        

Welcome back @Dae_Shaun_High_Hawk, I believe you have 3 problems in your code.

  • you should indent everything once after this line for them to all be in the while-true loop
  • also, the following line is irrelevant as you can not change the value of gold unless you collect coins, you should probably remove it
  • about the error you are getting, you don’t have anything after this statement:

so you should type in something or remove this line fully.

and an easier way to do this is

decoysBuilt += 1

it also says now after i did that, that it says i cannot write to protected property gold

Can you screenshot or explain a bit more? And also please post your new code

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.

1 Like

@Aya

like that ??

im not that good with the loops still haha

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

Delete the hero.gold = 0 statement. You don’t need that.

1 Like
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

indent this line and everything afterwards, for them to be included in 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

sorry for making this a hassle to have this stuff explained to me i am quite dumb sometimes haha

don’t forget this (20 chars)

I figured it out now thanks @aya & @abc

3 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.