buildXY not working as expected. Quirky behavior my bad, or a bug?


#1

Hello,

I am in the process of Defending the Garrison in the Backwoods Forest.
What I want to do is build “caltrops”.

Even though I’m equipped with a stone builder’s hammer and the caltrops belt, I’m having trouble building anything but a “fire-trap”.
During testing, this code will build a fire-trap fine:

loop {
   var enemy = this.findEnemies();
   if (enemy) {
      this.buildXY("fire-trap", 57, 29);
   }
}

However, if I replace the string above with “decoy”, “arrow-tower” or “caltrops”, my character just goes to the coordinates and starts chopping his sword - but no item gets placed, and the sword-chopping generates no enemy damage at all. The character seems to get stuck in a sword-chopping loop and never gets out of it (any code after this.buildXY(“arrow-tower”, 57, 29); is not executed as far as I can tell).

I’ve tried building a “fence”, which did work, and “caltrops” (when equipped with the caltrop belt) which does not work. Seems strange.

I just didn’t know whether I was doing something wrong or whether it is perhaps a bug of some sort.
Any thoughts on why this isn’t working as expected?


#2

All these stuff takes money.
Your hero will try to build them, fail because not enough money, then wait for the next game frame and try again (in case some money had fallen on him somehow :slight_smile: )


#3

Ah, thanks very much for the input!
However, I’m still kind of confused.

On levels that have coins, a counter shows up in the upper right of the game screen.
On levels that don’t have coins, there is no counter.

So, does this mean that the only levels that I can build “caltrops”, “arrow-tower” or “decoy” on is on levels that offer coins? I was working on the assumption that I can choose to build (rather than attack) on any level that I want to.

Also, if I didn’t have enough money to build a given item, shouldn’t there be an error message that points to this as the problem? As of now, I just get stuck in a loop and the code never progresses past buildXY.

Furthermore, if building these items take money, is there a list as to what each item costs? This info is not listed on the inventory text and I find no reference to this at all.

It all seems strange and bug-like, and this issue is holding me back on a number of levels.

Would very much appreciate further clarification!


#4

Once you get a Boss Star in Cloudrip Mountain, you will begin getting income at various rates. Using this, it is possible to build things on any level. Otherwise, you can only build things if coins are existent.

No, because there is nothing wrong with your code. Money you have/don’t have doesn’t constitute errors. Additionally, just because you can’t build at one time does not mean you can’t build it some other time. Therefore, an error message would not be accurate.

Decoys and caltrops cost 25, and arrow towers cost 75.


#5

The buildXY is not the only function that has this behavior: if you call cleave, it will block until the cleave it is ready.

You must always guard your build calls, just like the cleave calls. this.gold lets you know how much gold you have at the moment:

if(this.gold>=this.costOf("decoy"))
    this.buildXY("decoy",30,30);

#6

Awesome,

Thanks so much ChronistGilver and AdrianCgw!
It all makes sense now - I really appreciate the help.
Looking forward to that Boss Star in Cloudrip Mountain. :slight_smile:

All the best!