[Decoy Drill] Character stuck hitting the floor with sword after 3 decoy built


#1

Hi, i’m having trouble with the level Decoy Drill, i’m using the following code:

decoysBuilt = 0
loop:
    item = self.findNearestItem()
    if item and self.gold <=25 and decoysBuilt < 4:
        pos = item.pos
        x = pos.x
        y = pos.y
        self.moveXY(x, y)

    elif self.gold >= 25 and decoysBuilt < 4 :
        self.buildXY("decoy", self.pos.x-5, self.pos.y)
        decoysBuilt += decoysBuilt + 1
    elif decoysBuilt == 4:
        break
self.moveXY(14, 36)
self.say("Hey, i am done building "+decoysBuilt+" decoys.")

After building three decoy my character stay in place and keep hiting the floor with his sword until time run out, i really can’t see what’s wrong, any help would be very welcomed.

Thank you very much for your time, have a nice day.


#2

alright, i fixed it using

decoysBuilt = 0
loop:
    item = self.findNearestItem()
    if item and self.gold <=25 and decoysBuilt < 4:
        pos = item.pos
        x = pos.x
        y = pos.y
        self.moveXY(x, y)

    elif self.gold >= 25 and decoysBuilt < 4:
        self.buildXY("decoy", self.pos.x-5, self.pos.y)
        decoysBuilt = decoysBuilt + 1
    elif decoysBuilt == 4:
        break
self.moveXY(14, 36)
self.say("Hey, i am done building "+decoysBuilt+" decoys.")

I think i didn’t quite understand how “=” and “+=” work…gotta get back to previous level and check what i understood wrong.

edit:
Alright! I got it, it’s either “decoysBuilt = decoysBuilt +1” or “decoysBuilt +=1”

Sorry for useless post, hope it might at least help someone who make the same mistake. :slight_smile: