Hey guys. This is another level I am having a hard time going.
It is called decoy drill. I know you have to break the loop in order for the computer to follow the code on the bottom. Somehow, it did not seem to. It only did the code on what the break is on top of. Here is my code first.
loop:
decoysBuilt = 0
coin = self.findNearestItem()
if coin:
pos = coin.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
if self.gold>=25:
pos.x = pos.x - 5
pos.y = pos.y
self.buildXY("decoy", pos.x - 5, pos.y)
pass
if decoysBuilt >= 4:
break
self.moveXY(14, 36)
self.say("done building decoys!")
This makes sense to me. Somehow, the last two pieces of code are not done. Can you tell me why?
loop:
self.say("This statement is inside the loop!")
self.say("This is because is it one indent forward from the loop!")
break
self.say("This statement never gets reached :(")
self.say("This is because once *break* is found, the program immediately exits the loop.")
self.say("Therefore, the statements after the *break* never get run.")
self.say("This statement, however, is not inside the loop. ")
self.say("I get run after *break* is reached.")
Now I have the total opposite. The code after the break happened, but it happened at the start too fast. I want it to happen when I build 4 or more decoys. However, he did it at the start of the game.
loop:
collect coins
if enough to build a decoy
build a decoy
decoysBuilt++
Here the increment (decoysBuilt++) is not at the same level as the build decoy code. As a result, you’ll add to the number of decoys built even if you are not building one.
It should be like:
loop:
collect coins
if enough to build a decoy
build a decoy
decoysBuilt++