Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Sarven Shepherd infinite loop (Javascript)


I’m having a problem with Sarven Shepherd level, as it’s throwing me a infinite loop error and the character just stands still. I think it’s because it is looping on the first Yak… and I’m not sure how to remedy this.

while(enemyIndex < enemies.length) {
    var enemy = enemies[enemyIndex];
    if (enemy.type != "sand-yak") {
        while(enemy.heath > 0) { // If I comment this
        } // & this, it  works..

But when I remove while(enemy.heath > 0) and the curly brackets around attack, it seems to run fine, abit kind of funky as they hit the enemies a few times and run back to the X, etc. 761 health doesn’t seem to be enough health for this level.

I tried looking at other similar threads, but they don’t seem to help with the looping, and I dunno how I feel about necroing an old thread.


Its your spelling. Try You for got the L.

Im surprised the error didnt tell you “heath” isnt a method of enemy. Normally it would give a suggestion did you mean health? At least from my experience it has.


Oh wow, I didn’t catch that. lol
Yea it would of been helpful if it did threw an error about “heath”.