command troops to move east and attack any ogre they see
#use for-loops and findFriends
#you can use findNearestEnemy() on your soldiers to get their nearest enemy
loop:
friends = self.findFriends()
friend = self.findNearest(friends)
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
for friend in friends:
if enemy:
self.command(friend, “attack”, enemy)
if not enemy:
self.command(friend, “move”, {“x”: friend.pos.x + 10, “y”: friend.pos.y})
certainly not a code i would make just happened to be the last go around i was on. my indents are correct, just not sure how to show that on here.
I’ve read that find nearest shouldn’t be added to this code, but the code above was the only python code i could find for this level that wasnt completely terrible. His problem being his troops did nothing but run east. This is the 5th code chunk ive used and modified everyway i could think of.At this point im just looking for anyprogress past a red circle and the SAME FLIPPIN ERROR! All times i’ve deleted everything and tried fresh changing Variables,moving units 1 at a time, in groups, and all at once, using others broken code(This is a broken code-im rather sure i was able to fix his mistake, and once past the refference error im gravy).
This codes INTENDED goal is: -Create variable for an array of all friends.
-For each friend in the array stored in friends
-if there is an enemy-attack it
-if not an enemy - move x+10
-start over till no friend
im curious on if this needs an index or not but i can solve that myself later.
PROBLEM: the problem on every single time I run “friends = hero.findFriends()” no matter where its at or what its in, i get “ReferenceError: profile is not defined”
im not trying to define any new functions - im making a variable with a value.
It’s not an item issue, i’ve got the top glasses i can and the findFriends command is in its list.
What i dont understand, is how every other code ive looked at start with that variable combo somehow/someway/somewhere no matter what. Even tried it as " for friend in self.findFriends():"
Appreciate any feedback, because im completely struck. GL mates