Hunting Party, possible bug or operator error?(python)


#1

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


ReferenceError: profile is not defined (python)
#2

Could you please format your code according to the Discourse FAQ? It would help out a ton. You just have to put three backticks around your code.


#3
# 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})

#4

First of all, don’t actually define friend because you do that in the for loop and second of all I believe it was the same error as in this topic. I reccommend hanging in there until the problem is solved, which at max may take around a day.


#5

not to be off topic, but can I ask why I would do it inside the for and not before it? how is it suppose to know what “friend” & “friends” are, wouldnt that be telling it the same thing as

for some_word_no_ones_ever_heard in some_array_that_doesnt_exist

they aren’t very user friendly in terms of explaining much of anything at all lol


#6

ouch, well thats minorly depressing :confused: how do i get my geek on now? Lol


#7

Simply because friend is a unit in the array friends. So when you use a for loop, you take out that friend and tell it what to do from the for loop.


#8

ah well yeah, ok, i see what you’re saying I think. in the 1st 4 lines after loop?
went though so many options i was game to try anything haha. fixed other persons error and hit run…I would have only put friends = hero.findFriends() then on to for loop


#9

and it must be a bug because i changed glasses, changed up code and same error, just on enemy this time…

enemy = hero.findNearest(hero.findEnemies())
hero.moveXY(60, 72)
if enemy:
    hero.attack(enemy)
else:
    pass

hero.moveXY(64, 24)
if enemy:
    hero.attack(enemy)
else:
    pass

hero.moveXY(88, 60)
if enemy:
    hero.attack(enemy)
else:
    pass

#10

Thanks for the details–I found the bug. Should be fixed now, if you try again. (You may need to clear your browser cache.)


#11

appreciate it buddy ty =]


#12

no problem dude :grinning:


#13

took a couple day break thinking id come back to this being fixed now its a cannot read protected property error…what the deuce? lol


#14

I seriously have no idea what is with all these bugs but I’ve been getting that one too.


#15

Me neither. I am still getting bugs.