Touch of death help


#1

I have tried very hard to debug my code, but I have not found the error.
The message is:

Unreachable after return

Here is my code:

loop {
    var enemy = this.findNearestEnemy();
    if (enemy) {
        var distance = this.distanceTo(enemy);
        if (distance < 15) {
            // Cast "drain-life" on the enemy.
            this.cast("drain-life", this.findNearestEnemy());
        }
        else {
            // Attack the enemy with your staff.
            this.attack(enemy);
        }
    }
}

#2

At least edit your post using : “FAQ - Check Before Posting” pinned post


#3

Edited Feintys post to have better punctuation and indentation.

I don’t understand the error though. There is no return-statement in your code. Can’t help you here, sorry.


#4

Same for me, no evident mistake.
I could just advise you to replace:
this.cast("drain-life", this.findNearestEnemy());
by
this.cast("drain-life", enemy);

Are you sure you show us all the code ? Where the error took place in the code ?


#5

Yes this is all my code and it says

Unreachable 'while' after 'return'

#6

Reclassified as bug.


#7

You have this at the top of your code from hitting the “Comment out my code” button on the infinite loop modal at some point:

return;  // Commented out to stop infinite loop.

So that’s why it’s giving you that message.


#8

I found this out recently and fixed my code btw thanks for the help