So according to my code my character goes to the flag and then picks it up, then nothing unless there’s an enemy. The problem is once I pass the barrier to the next area my character just continues on right regardless if there is a flag or enemy and I don’t understand why. Help, please?
"
loop:
enemy = self.findNearestEnemy()
flag = self.findFlag("green")
if flag:
flagpos = flag.pos
x = flagpos.x
y = flagpos.y
self.moveXY(x, y)
self.pickUpFlag(flag)
else:
if enemy:
if self.isReady("cleave"):
self.cleave(enemy)
else:
self.attack(enemy)
self.bash(enemy)
else:
"
Ok I’m getting very irritated at this point. No matter what code I write my character just goes all the way to the right of the second area and keeps trying to go right as things are attacking it. It only starts attacking when my character says “I can’t get there!” and breaks whatever is making it go right.
You might consider adding some code to disregard the sand-yaks. If your hero ignores them then even if they run into him as they go by they don’t do damage but if he attacks them then they attack him.
also, the code you posted is missing indents on your attack and bash commands
I think the issue is that once your hero is going after a flag he cannot break that command until he gets it or until he fails and because you use moveXY he doesn’t change his path if you move the flag until he gets to the original position of the flag.
I got my character to follow the flag, and now the only issue I run into is I don’t know how to keep it from attacking the yaks. I don’t see any identification or names for them to use in my code and I’m not sure how to differentiate them from the skeletons using things like “findNearestEnemy”
it’s a lesson in one of the other levels in this world. You might need the right glasses to do it.
it’s enemy.type and the type is "sand-yak"
put that together to not attack if the enemy.type is a sand-yak.
if the enemy type is sand-yak
do nothing
otherwise
attack
loop:
enemy = self.findNearestEnemy()
flag = self.findFlag("green")
if enemy:
if enemy.type /= "sand-yak":
self.attack(enemy)
else:
else:
if flag:
if self.distanceTo(flag) < 40:
self.pickUpFlag(flag)
else:
else:
This code should attack anything that isn’t a sand yak, shouldn’t it? My character doesn’t attack the yaks now, but it doesn’t attack the skeletons either. It just sits there and dies.
You need to indent most of your code by one indentation level, in order to place it inside the loop. Also, the proper code to check if something is not something is !=, not /=. One last thing: Empty else blocks will break your code. Don’t put them in at all.