The code's being an idiot


#1

I am doing the level “Decoy Drill”.
What’s wrong with my code?

# We are field testing a new battle unit: the decoy.
# Build 4 decoys, then report the total to Naria.
# Each decoy costs 25 gold. Use the Quartz Sense Stone
# to know when you have more than 25 gold with self.gold.
# Keep a count of decoys you built as you go along.
# Break out of the loop when you have built 4.
decoysBuilt = 0
loop:
    item = self.findNearest(self.findItems())
    if self.gold>=25:
        self.buildXY("decoy", self.pos.x, self.pos.y)
        decoysBuilt+=1
    else:
        pos=item.pos
        x=pos.x
        y=pos.y
        self.moveXY(x, y)
    if decoysBuilt=4:
        break
self.say("Done building decoys!")
# Go to Naria and say how many decoys you built.
self.moveXY(14, 36)
self.say("I built "+decoysBuilt+" decoys!")


#3

The problem with claiming the “code is being an idiot” is that it usually back fires…

One, it would help if you told us what your code did or didn’t do…

But here is the answer anyway:

‘=’ is an assignment.

if decoysBuilt = 4:

sets decoysBuilt to 4

‘==’ is a conditional (asks about being equal)

if decoysBuilt == 4:

does things IF decoysBuilt “is-equal-to” 4


#5

thanks

(there is no :heart: button)


#6

You were probably wondering what this meant. Well this popped up while I was typing “thanks”:
“Post must be at least 20 characters. Have you tried the :heart: button?”


#7

:smiley: You have to wave your mouse over the post