Hi!! I’m stuck in this lvl!! Help me plz???
Code:
// Use your new skill to choose what to do: this.now()
loop {
// If it’s the first 10 seconds, fight.
if (this.now() < 10) {
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
if (this.distanceTo(enemy) < 10 && this.isReady(‘cleave’)) {
this.cleave(enemy);
} else {
this.attack(enemy);
}
}
}
// Else, if it's the first 30 seconds, collect coins.
if ((this.now() >= 10) && (this.now() <= 30)) {
var item = this.findNearest(this.findItems());
this.move(item.pos);
}
// After 30 seconds, join the raid!
if (this.now() > 30) {
var flag = this.findFlag();
if (flag) { this.pickUpFlag(flag);}
enemy = this.findNearest(this.findEnemies());
if (enemy) {
if (this.distanceTo(enemy) < 10 && this.isReady('cleave')) {
this.cleave(enemy);
} else {
this.attack(enemy);
}
}
}
}
Hello, Yariel, and welcome. Please format your code according to the FAQ.
Your problem is the line if (this.distanceTo(enemy) < 10 && this.isReady('cleave')) {
. Your character only attacks if the distance is greater than ten. However, when your character moves to attack, the distance is reduced, so they don’t attack. Separate this if-statement into two blocks.
I don’t know how 2 format…
Code:
// Use your new skill to choose what to do: this.now()
loop {
// If it’s the first 10 seconds, fight.
if (this.now() < 10) {
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
if (this.distanceTo(enemy) < 10 {
this.isReady(‘cleave’))
this.cleave(enemy);
} else {
this.attack(enemy);
}
}
}
// Else, if it’s the first 30 seconds, collect coins.
if ((this.now() >= 10) && (this.now() <= 30)) {
var item = this.findNearest(this.findItems());
this.move(item.pos);
}
// After 30 seconds, join the raid!
if (this.now() > 30) {
var flag = this.findFlag();
if (flag) { this.pickUpFlag(flag);}
enemy = this.findNearest(this.findEnemies());
if (enemy) {
if (this.distanceTo(enemy) < 10 && this.isReady(‘cleave’)) {
this.cleave(enemy);
} else {
this.attack(enemy);
}
}
}
}
Is this what u mean??
But, I just said, look at the FAQ. It will tell you how to “post your code with radiant, harmonious formatting”. It is there, I promise.
this.isReady("cleave")
is not a command. You must use it in an if-statement.
if (this.distanceTo(enemy) < 10) {
if (this.isReady("cleave")) {
//Do stuff
Ohhhhhh… I’ll see if that works. Thx!! I’m new here to the forum and I really didn’t think of looking at the FAQ I hope I haven’t annoyed u and I’ll read the FAQ for future posts.