To continue my first post about medical attention (it got locked)

2 things, One, the code i found on the other posts doesn’t work. 2. Here is my code

Ask the healer for help when you’re under one-third health.

loop:
enemy = self.findNearestEnemy()
currentHealth = self.health
healingThreshold = self.maxHealth / 3
if enemy:
# move to the healing point and say, “heal me”.
if healingThreshold:
self.moveXY(65, 46)
self.say(“heal me”)
# Otherwise, attack. You’ll need to fight hard!
else:
self.attack(enemy)
self.attack(enemy)
if self.isReady(“cleave”) and self.distanceTo(enemy) < 5:
self.cleave(enemy)

( i had to delete one if the notes it was in the way)

and also the indentations got removed

Hint: use 3 backticks before and after your code to format it properly.

See the FAQ for more.

Main problems I can tell:

  • Your code is not formatted properly. (Hint: ```)
  • healingThreshold is always truthy (unless your maxHealth is 0).

Other nitpicks:

  • Cleaving with the long sword is almost useless after the forest levels (basically most ogres have > 50 health, cleave only does 15 damage).
  • You are doing too many “blocking” actions in the loop per iteration; try to do only at most one (except healing; that will take two)
  • You’ll need sufficient health (you didn’t say); assuming basic warrior types, maybe 600+?
  • The seeds generated for this level are completely messed up (for me, at least). So once you get your code right, you’ll probably have to submit multiple times.
1 Like

i have 313 health. Also what is a backtick, “blocking” action and how is healingThreshold truthy (and what does truthy mean) ( I started last week I am fairly new to python and other programing languages.)

also i am free to play.

“Truthy” means that the expression evaluates to True. (Likewise, “Falsy” means the expression evaluates to False.) Pretty sure this was covered in the forest campaign.

healingThreshold is always truthy because x / 3 (for x ≠ 0) is a non-zero number, and all numbers except 0 are truthy.

If an action takes some time to complete it is considered “blocking” your code execution. (Hover over the spell palette to check; ie. self.attack is “blocking” because it takes almost 1s, self.findNearestEnemy is not “blocking”, self.moveXY is “blocking” because you can’t do anything else until reached your target position.) If an action is “blocking”, your hero is unable to do anything else until the action is complete. This is why you’ll want to have as few blocking actions as possible, to be able to choose to do what action as many times as possible.

The backtick (`) should be on the key with the tilde (~).

I’m also free to play and I had plenty of gems by the time I got to the desert level…you could simulate some games…

1 Like

I’ve already told you that healingThreshold is always truthy, so fix that.

Hint: compare it with another variable.

My original problem was that my character would sway from side to side saying heal me

That’s your problem: since healingThreshold is always truthy, your hero will only sway side to side and say "heal me"

So…compare it with another variable, and do what the comment says:

Ask the healer for help when you’re under one-third health.
Otherwise, attack. You’ll need to fight hard!

This is my new code

loop:
    enemy = self.findNearestEnemy()
    currentHealth = self.health
    healingThreshold = self.maxHealth / 3
    if enemy:
# move to the healing point and say, "heal me".
        if currentHealth < healingThreshold:
            self.moveXY(65, 46)
            self.say("heal me")
    # Otherwise, attack. You'll need to fight hard!
        else:
            self.attack(enemy)
            self.attack(enemy)
        if self.isReady("cleave") and self.distanceTo(enemy) < 5:
            self.cleave(enemy)


How much health do you recommend?

This topic is now closed. New replies are no longer allowed.


If at first you’re locked, try again? Sounds wrong to me. Use existing topics! We got them for a reason. If other people’s code doesn’t work, try to find out why and post an updated version.


Your newest code has the problem that you only heal when an enemy is present. If you are below the threshold, but there is no enemy, then you won’t go healing, period. Try to change that first.
Any further discussion in an existing topic please.

1 Like