Bug on Nalfar Sacrafice

So I was playing around in sacred statue but then out of the blue it said I had -2129 healh out
of - 629 Please help

Can you send me a Clear Screenshot of why this is happening?

2 Likes

Hmm, I seem to have this problem too. But not on sacred statue, is on Cavern Survivals.
You get instantly-ripped when you cast sacrifice, I get it. Try not to sacrifice within a for-loop and see if it works.

Instead of:

for friend in friends:
    hero.cast("sacrifice", friend, self)

Do:

friend = hero.findNearest(hero.findFriends))
if friend:
    hero.cast("sacrifice", friend, self)

You forgot the start parenthese:

friend = hero.findNearest(hero.findFriends())
if friend:
    hero.cast("sacrifice", friend, hero)

and use hero not self, it’s confusing

1 Like

Thanks(200000000000000000000 chars)

But now it has this:

Click on Comment Out My Code, it mightn’t work from the first time, so do that as long as it asks you to

1 Like

Thanks it worked​:smile::smile::smile::smile::smile:

1 Like

You’re welcome, but now your code wouldn’t run because it is commented (comments don’t run) on the first line, before you remove it, try fixing the error, or post your code so we can help you :slight_smile:

How do I fix it?:thinking::thinking::thinking::thinking:

And here is my code:

return  #Commented out to stop infinite loop.
# Walk to a few points around the ogre camps, defeating any enemies along the way.
# Visit the statue to begin the event.
# Stand your ground and defeat the attacking ogres.
def onSpawn():
    pet.moveXY(-4, 56)
pet.on("spawn", onSpawn)
# Hint: fight close to the statue for it's assistance during the battle.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
    if hero.isReady("summon-burl"):
        hero.cast("summon-burl")
    if hero.isReady("summon-undead"):
        hero.cast("summon-undead")
    friends = hero.findFriends()
    for friend in friends:
        hero.cast("sacrifice", friend,self)
    if hero.health >= 14000:
        break
        pass
# After you defeat all of the waves, you will have to face off against the Ancient Cyclops!
hero.moveXY(62, 70)
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.attack(enemy)
        if hero.isReady("summon-burl"):
            hero.cast("summon-burl")
        if hero.isReady("raise-dead"):
            hero.cast("raise-dead")
        if hero.isReady("summon-undead"):
            hero.cast("summon-undead")
            
    friends = hero.findFriends()
    for friend in friends:
        if hero.isReady("sacrifice"):
            hero.cast("sacrifice", friend, self)
     

Something important to be aware of is that you cannot make 2 while-true loops

while true loop go on forever (or technically until the level is finished) but what you can do here is that you used the condition of the hero’s health to know when to break out. So you can change the first while true loop to while hero.health < 14000 and for the second one, you can make it: while hero.health >= 14000

1 Like

I’ll try that :thinking::thinking::thinking::thinking:(20 chars).

No, using conditions in while true loops in CodeCombat makes it think they’re infinite, instead use

while True:
    if not condition:
        break
    doStuff()
2 Likes

The second while-loop is the main attack function of the code, so you don’t even need to make a statement anymore.

Try the code below. I have commented explanations.

# Walk to a few points around the ogre camps, defeating any enemies along the way.
# Visit the statue to begin the event.
# Stand your ground and defeat the attacking ogres.

def onSpawn():
    while True:   # Use while true so your pet always don't affect your hero.
        pet.moveXY(2, 56)

pet.on("spawn", onSpawn)

while True:
    enemy = hero.findNearestEnemy()
    if hero.health >= 10000:   # Try to make the health lower, or else the mass amount of corpses will bug your game.
        break
    if enemy:
        hero.attack(enemy)
    if hero.isReady("summon-burl"):
        hero.cast("summon-burl")
    if hero.isReady("summon-undead"):
        hero.cast("summon-undead")
    for index, friend in enumerate(hero.findFriends()):  # This might be useful in the future when you want to use them for defendPoints.
        if hero.isReady("sacrifice"):  # You forgot to check for the ability!
            hero.cast("sacrifice", friend, self)
        #pass  -- Don't need this to close.

hero.moveXY(62, 70)
while True:
    enemy = hero.findNearestEnemy()
    if hero.isReady("summon-burl"):
        hero.cast("summon-burl")
    if hero.isReady("raise-dead"):
        hero.cast("raise-dead")
    if hero.isReady("summon-undead"):
        hero.cast("summon-undead")
    # I've moved the summoning code to the front to let you keep summoning
    if enemy:
        hero.attack(enemy)
1 Like

@phoenixRider2022 Does it work for you now?

1 Like

Yeah it worked(20 chars)