Need help with medical attention


#1

MY code is not working i got so mad I am trying to just find the code some wear
loop:
currentHealth = self.health
healingThreshold = self.maxHealth / 1.5
# If your current health is less than the threshold ,
# move to the healing point and say, “heal me”.
# Otherwise, attack. You’ll need to fight hard!
enemy = self.findNearestEnemy()
if currentHealth < healingThreshold:
self.moveXY(65, 45) and self.say(“heal me”)
else:
if enemy:
if self.isReady(“cleave”) and self.cleave(enemy):
self.attack(enemy)
self.shield()
self.attack(enemy)
self.shield()
self.attack(enemy)


#2

srry if code does not look like it should I don’t know how to fix it :frowning:


#3

Hey there, to format your code highlight it and press the </> button.
Also, we have a problem helping you if you do not state what is happening. Why can’t you pass the level? Any Error messages? What language are you using? (Looks like Python to me)
It seems that you should not have and, it should be like this

if currentHealth < healingThreshold
self.moveXY(65,45)
self.say("Heal Me!")

Also, the attacking part should be changed. What is the “and” thing you are using? I did a little bit of research, and “and” in Python is like && in Javascript, a conditional operator.
So, the attacking part should be changed to where if you can cleave, you cleave the nearest enemy, and if you cannot, then you simple attack them. That would look like this:

if self.isReady("cleave"):
self.cleave(enemy)
else:
self.attack("enemy")

If it still doesn’t work, reply to me.
Be sure to remember that Python needs to be indented to work.
Good Luck!
PS, read the FAQ before posting. Thanks!


#4

use type three backpacks (`) before and after your code to make it, well, codey


#5

Hello Derek_Brown, I think this is how you wanted to format your code?


Your Code: (Python)

loop:
	currentHealth = self.health
	healingThreshold = self.maxHealth / 1.5
	enemy = self.findNearest(self.findEnemies())
	if currentHealth < healingThreshold:
		self.moveXY(65, 45) and self.say("heal me")
	else:
		if enemy:
			if self.isReady("cleave") and self.cleave(enemy):
				self.attack(enemy)
				self.shield()
				self.attack(enemy)
				self.shield()
				self.attack(enemy)

Looks like eab201903977 took care of this before I could :smile: I am also figuring out how to best complete medical attention. As eab201903977 mentioned, you will want to reformat your “if cleave is ready” code block. You might also consider using the new structure as a chance to do something more, such as: go wait for a new enemy if there are no enemies in sight! :wink:


Example: (Python)

if enemy:
	if self.isReady("cleave"):
		self.cleave(enemy)
	else:
		self.attack(enemy)
		self.shield()
		self.attack(enemy)
		self.shield()
		self.attack(enemy)
else:
	self.movexy(50, 40)

I think I see where your confusion is. Earlier in the program you use: “self.moveXY(65, 45) and self.say(“heal me”)” to make the process of moving and healing shorter and more compact. I tested it and it works great by itself. You applied the same logic to the isReady and Cleave. The reason it doesn’t trigger is because this logic is inside a if/and argument. In short your program is trying to compare isReady to the cleave command states (and determine if they are equal) Rather than doing one command after another like I think you are trying to accomplish.

I hope this helps!
Cheers :beers:
AlCH3MlST

Don’t be afraid to go out on a limb. That’s where the fruit is - H. Jackson Browne


#7

thnx guys i past it just needed some help :smile:


#8

what do you meen flagged


#9

That’s an automatic response when someone deletes a message


#10

Umm then what would be the full code?


#11

We don’t post full solutions, that goes against the forum policy. If you need help, please post your code and tell us what problems you are experiencing with it.