34. Agrippa Refactored

I keep using the code I am attaching and it keeps failing. I have no idea why this code won’t work.

Screen Shot 2020-03-30 at 2.26.13 PM

def cleaveOrAttack(enemy):
# If “cleave” is ready, cleave; otherwise, attack.
if hero.isReady(“cleave”):
hero.cleave(enemy)
else:
hero.attack(enemy)
pass

while True:
enemy = hero.findNearestEnemy()
if enemy:
distance = hero.distanceTo(enemy)
if distance < 5:
# Call the “cleaveOrAttack” function, defined above.
cleaveOrAttack(enemy)

Hi Jason and welcome to the forum!

Please be sure to properly format your code…you can learn how here: [Essentials] How To Post/Format Your Code Correctly

With that being said, your code looks good…based on the screenshot, your formatting looks good too. How about a pic of your weapons/armor? You do have the Long Sword equipped, right?

I am a computer science teacher, so I have the education version. In this version their does not seem to be a way to equip other gear sadly. I think that would make this better for my students though.

I just found the code that code combat said works in the teacher section and mine is identical. Very odd. I want to get through all of these before my students do them.

Thank you for your help :slight_smile:

def cleaveOrAttack(enemy):
    # If "cleave" is ready, cleave; otherwise, attack.
    if hero.isReady("cleave"):
        hero.cleave(enemy)
    else:
        hero.attack(enemy)

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        distance = hero.distanceTo(enemy)
        if distance < 5:
            # Call the "cleaveOrAttack" function, defined above.
            cleaveOrAttack(enemy)ype or paste code here

Oh, ok. I would not know the idiosyncrasies of the education version. Yes, your code/formatting is solid. If you do not have the option to change hero/gear, we’ll need someone more familiar with that version to respond.

Just in case, do you have the Game Menu option at the top of your screen?:


If you do, you would be able to make changes, via the Change Hero option.

I truly appreciate the help. Here is what mine looks like.

Ok, we need help… @Chaboi_3000, @MunkeyShynes, gentlemen, I’m stuck on this one and not sure who to pass on to, if not one of you.

1 Like

Jason, while we’re waiting, under Methods, what is showing for your weapon?
image

I think this is what you mean?

Screen Shot 2020-03-30 at 3.40.42 PM

Yes, that’s it. And, it shows that you do have the Long Sword equipped, as that is the only one that allows Cleave. Next step…Restart the level via the the button at the upper right. You will need to redo your code, but you have a copy of it saved here in this topic.

I tried that as well. :frowning:

Edit: the google drive was grainy. I just uploaded it to YouTube: https://youtu.be/ErXyb6grwrM

Here is a video of what’s happening. It might take a second to render.

Ok, that helps! Notice your health at the start? It is quite low. Since you don’t have the Change Hero option, I’ve no idea how to resolve…will need the guru’s to chime in.

Here’s my hero, but this is via the campaign version, not the edu:

1 Like

Very odd. I discovered I was able to change my character, so changed it to Hattori and Alejandro and I received the same result. I then figured I would try one more character (Okar) and low and behold it worked.

This kind of needs fixed. It doesn’t say anywhere that you have to change your character.

Thank you for your help Dedreous. I wouldn’t have even of thought to do this without you telling me.

You are very welcome :slight_smile:

In the campaign version, armor equates to health, so the better you have, the more health you have. If this gets figured out and you end up able to change/purchase armor (via in game gems), be careful of what you choose…not all armor is needed, nor the best fit for the situation.

I’m most likely going to buy the the lifetime subscription when this runs out. This is FUN. Definitely the most fun I have had coding. :slight_smile:

2 Likes

heh…I hear ya there! I get as big a kick out of helping folks where able…the coding is just secondary :wink:

1 Like