Stuck in "Decoy Drill"

As soon as my hero builds 1 decoy, the loop gets broken and he goes tell the NPC he’s build 4 decoys. I have no idea why. The tutorial video uses Decoys build += 1 instead of + 1, but I get an error code when trying that and I’m not sure what the difference is.


decoysBuilt = 0
    coin = self.findNearestItem()
    coinpos = coin.pos
    selfpos = self.pos
    self.moveXY(coinpos.x, coinpos.y)
    if >= 25:
        self.buildXY("decoy", selfpos.x, selfpos.y)
        decoysBuilt = decoysBuilt + 1
        if decoysBuilt = 4:
self.say("Done building decoys!")
self.moveXY(14, 36)

self.say("ey yo I've build " + decoysBuilt + " decoys hook me up with those gems")

Your statement if decoysBuilt = 4 is incorrect. You use one equals sign, which means assignment. Perhaps you meant to use two equals signs, for equality comparison?

1 Like

That fixed it, thank you! I assumed the “if” played the role of making it an equality comparison, and had forgotten about the ==.

Could you or someone else also please shed some light on why the video tutorial uses decoysBuilt = decoysBuilt += 1 instead of decoysBuilt = decoysBuilt + 1?

I don’t think the tutorial uses decoysBuilt = decoysBuilt += 1. It’s probably decoysBuilt += 1. += is a Python shortcut that condenses incrementing variables.

1 Like