loop:
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy.pos)
if distance < 10:
self.attack(enemy)
self.moveXY(40,37)
Thanks so much. The same code is now working. The only difference is that now I am using some updated gear and I have gained a few levels playing other levels.
Thank you!!
Clare
No Problem if you need anymore help ill see what I can do.
Hello all, Iâve got the same problem as the others. I estimate my success rate to about 10%. The character almost always successfully kills the first wave of enemies coming from the left, but does not move quickly enough towards the second wave coming from the right which kill the peasant. Increasing the attack distance to 20 or 30 does help sometimes, but not always.
I play with javascript, and my code is essentially the same as @clare12345âs, only a bit more compact, e.g.
var E = this.findNearest(this.findEnemies());
if (this.distanceTo(E) < 10) {
this.attack(E);
} else {
this.move({x: 40, y: 37});
}
Further, my figher character is level 12 with speed 8, and the level fails with either the longsword (cleave) equipped or the faster short sword. Using cleave does help, but this randomly depends on the number of enemies that are currently in cleaving range. Complicating the tests with checking the length of the enemy list etc does not help at all.
One bug I noticed is that the character seems to get stuck in non-attacking, non-noticing move mode when it is already on the XY-coordinate that the move command directs it to.
Follow-up: buying and equipping the âsoftened leather bootsâ instead of the âcompound bootsâ works for me: the character does not dawdle nor bumps into the peasant but niceley stays within range:
var E = null;
loop {
E = this.findNearest( this.findEnemies() );
if (this.distanceTo(E) < 10) {
if (this.isReady("cleave"))
this.cleave(E);
else
this.attack(E);
} else {
// instead of the failing? this.move({x: 40, y: 37});
this.moveXY(40, 37);
}
}
Yeah, sorryâI need to do a big refactoring to get the move
boots to work without dropping a frame every small movement. For now, just stick to moveXY
boots.
can anyone post how to beat pheasent protection because im stuck
Hello Joshua,
it is usually not the case that we (as community) hand out code directly, but you present your code and we tell you how to improve.
Despite from that, this post contains multiple hints and solutions. Did you actually read it?
Greetings,
J_F_B_M
yes but iâm at school and i got free time so im usually on at this time. I bought alot of stuff so maybe it would help but im stumped
Merged Double-Post
alright i tried canât figure it out
for real i cant beat it
Second Time:
What did you try, and what do you think why it wonât work? Post your code, maybe it is just a problem with indentations (happens more often than one might think).
Iâm stuck as well. My code is:
loop {
var enemy = this.findNearestEnemy();
var distance = this.distanceTo(enemy);
if (distance < 10) {
this.attack(enemy);
} else {
this.moveXY(40, 37);
}
}
Any thoughts on whatâs wrong with the code?
That looks right, but what seems to be going wrong with the level? Is there an error? Is the peasant dying, and if so, what is your hero doing that doesnât protect the peasant?
Could be that youâre trying to get the distance to enemy, but enemy is potentially null where you check it.
loop {
var enemy = this.findNearestEnemy() //can return null
var distance = this.distanceTo(enemy) //checks against null
...
}
You should check if (enemy) {...}
. To actually avoid some issues, you should check the distance in chain with the enemy.
loop {
var enemy = this.findNearestEnemy();
if (enemy && this.distanceTo(enemy) < 10) {
this.attack(enemy);
} else {
this.moveXY(40, 37);
}
}
This code firsts checks if there is an enemy, and if this is the case, checks the distance to it. If there is no enemy, this.distanceTo(enemy)
is never checked.
Eductation Part, it is not necessary to read this
This is a nice feature of modern programming languages which allows you to chain checks which otherwise would fail. Most often this is used to first check a precondition that absolutly must be valid before the actual condition is checked.
//avoid dividing through 0
if (a != 0 && b/a = 0.5) {...}
//avoid targetting non-existent enemys
if (enemy && this.distanceTo(enemy) < 10) {...}
In the early time of programming, both checks would have caused an error. Todays compilers are pretty advanced compared to that.
Hero doesnât get back to X (40,37) on time to defend peasant from the first wave of attacks coming from the left. When I tried reducing distance, she notices the first attackers too late, when I tried adding to it, she wanders out too far.
Thanks for trying to solve my problem! Unfortunately the peasant still dies at the first wave of attacks coming from the left (hero doesnât get there on time)
Ok, my guess was wrongâŚ
Which hero do you use? Anya/Tharin? How much bonus-speed do you get from shoes?
Iâm using Anya, my speed is shown to be capped at 8 no matter what shoes I use (I have the ones that use move() instead of moveXY() as well but it doesnât work out with those either)
I just checked on your account and it looks like itâs working now; did anything change? Or are you still somehow seeing the loss?
Hi Nick, yes the problem was on my part â I was using the simple sword to attack instead of the cleaver. It didnât kill the ogres in time thatâs why the hero was late to arrive to the left side. I was using the sword in the previous mission and didnât think to change it for this level. Thanks for the help!