Decoy Drill Help; It doesn't stop building decoys


#1

This is my code

  loop:
    item = self.findNearest(self.findItems())
    if self.gold < 25 :
        self.moveXY(item.pos.x, item.pos.y)
    else:
        self.buildXY("decoy", self.pos.x - 2, self.pos.y -2)
        decoysBuilt = decoysBuilt+1
    if decoysBuilt >= 4:
        self.moveXY(14, 36)
        self.say("Done building decoys!")
        self.say(decoysBuilt)

Thanks!


Decoy Drill Javascript
#2

You have to break out of the loop before you go to tell Naria your amount of decoys.


#3

That’s what I tried, and it never stops.
Here’s my code.

We are field testing a new battle unit: the decoy.

Build 4 decoys, then report the total to Naria.

decoysBuilt = 0
loop:
item = self.findNearestItem()
if item:
pos = item.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
pass
# Each decoy costs 25 gold.
# Know when you have more than 25 gold with self.gold
if self.gold >= 25:
newX = self.pos.x - 5
newY = self.pos.y
self.buildXY(“decoy”, newX, newY)

    # Keep a count of decoys you built as you go along.

if decoysBuilt == 4:
    # Break out of the loop when you have built 4.
    break
    pass

self.say(“Done building decoys!”)
self.moveXY(14, 36)

Go to Naria and say how many decoys you built.


#4

You need to iterate decoysBuilt, either with decoysBuilt = decoysBuilt + 1 or decoysBuilt += 1. I will leave it to you to figure out where it goes.

Also, I see you only joined three days ago. Before you post again you should probably read the FAQ and learn how to properly post your code. I’m sure someone will come along and fix it this time, but you should know it for the future.


#5

Where would the FAQ be? And second, the code I typed is still causing the sprite to build more than one or less.


#6

Here’s the FAQ. You can also find it by opening the “hamburger” menu (the icon that has three horizontal lines near the top-right of the screen) and clicking “FAQ”.