Cursed Valley Trouble


#1

Hi, I really need help on this level, the Cursed Valley. As far as I can tell, my code is correct, but my hero always dies before the last skeleton shows up or the next potion appears.

Hear’s my code:

while (true) {
var enemy = hero.findNearestEnemy();
// Attack if enemy exists AND enemy.team is “ogres”
// AND enemy.type is "skeleton"
if (enemy && enemy.team === “ogres” && enemy.type === “skeleton”) {
hero.attack(enemy);
}

var item = hero.findNearestItem();
// Collect if item exists AND item.type is "potion"
// AND hero.health is less than hero.maxHealth / 4
if (item && item.type === "potion" && hero.health < hero.maxHealth / 4) {
    hero.moveXY(item.pos.x, item.pos.y);   
}

}


#2

Hello! You can try taking your if (enemy && enemy.team === "ogres" && enemy.type === "skeleton") { take out the if enemy and place it into it’s own statement, placing the if (enemy.team === "ogres" && enemy.type === "skeleton") { inside of this statement. See if that helps. :slight_smile:

PS - Next time format your whole code please, it helps!


#3

Sorry, I really didn’t mean to format it at all, it was an accident. How do you make your text have that grey background?


#4

And I tried your suggestion, but my hero still dies before the next potion or skeleton appears. I feel like there is something wrong with the level and not with my code.For instance, your hero is supposed to slowly lose health, my hero does slowly lose life, but then all of a sudden, I lose a thousand health!


#5

I see! Well first and for-most, to format your code, put the dashes right before it. The dashes are found in the top right hand corner right next to the 1 key. Put one of them before and after what you want to format. OR you can highlight your code and press the “</>” button when posting a comment, it will format the highlighted section for you! Now as far as your coding problem. What gear are you using? And can you post your code fully formatted please?

Also! Here is something you can try, define a variable that will determine the health for you. For example var quarter = hero.health <= hero.maxHealth / 4 ; Then you can replace this with your current hero.health < hero.maxHealth / 4 in your if statement.


#6

I am using the worn dragonplate helmet, the worn dragonplate, the worn dragonshield, and the runesword.

here’s my code so far:

while (true) { var enemy = hero.findNearestEnemy(); // Attack if enemy exists AND enemy.team is "ogres" // AND enemy.type is "skeleton" if (enemy) { if (enemy.team === "ogres" && enemy.type === "skeleton") { hero.attack(enemy); } } var item = hero.findNearestItem(); // Collect if item exists AND item.type is "potion" // AND hero.health is less than hero.maxHealth / 4 if (item) { if (item.type === "potion" && hero.health < hero.maxHealth / 4) { hero.moveXY(item.pos.x, item.pos.y); } } }

And again, I don’t think the problem is in my code but in the level itself.


#7

Could you say your sessionID or your nickname in the game? I’ll try to research your problem.


#8

Sure, my username is

COD3_BR3AK3R

I don’t know how to find my sessionID.


#9

I see. Thx. Something weird happens on 44 second - your hero health is 1029 and the next frame it’s 290. That’s why you can see the last skeleton. But why it’s happening … I’ll write when I find the reason.


#10

Yah, I had noticed that and it didn’t seem right. Thanks for helping!


#11

Found it! Items can appear in four points and if your hero stand on one of the spots, then it’s possible to collect it when an item appear. Coins are cursed and damage your hero. I fixed the problem and now items don’t appear in the hero’s position. If you still have this problem try to clear cache in your browser.


#12

Glad the problem was solved! Sorry I couldn’t be more of assistance.