Goalkeeper level advise


#1

i’m trying to locate the y of the fireball but i can’t please advises how i can modify the code so i can get the y pos of the ball


#2

Since the function findByType returns a list, you need to set the first item in that list as ball. You do this by asking for the thing at index 0.

You do this by putting brackets with the wanted index after the list:

ball = self.findByType("ball")[0]

#3

i made the change but i still face the same error can't read property pos of undefined

    loop:
    friend = self.findNearest(self.findFriends())
    ball = self.findByType("ball")[0]
    for friend in self.findFriends():
        self.command(friend, "move", {"X" : 15 , "Y" : ball.pos.y})

#4

What kind of glasses are you using?


#5

hardened steel glass


#6

That might be the problem then. You can’t see far enough to spot the ball.


#7

but i can see friends but not enemies nor the ball


#8

Yea it’s a little bit strange. Another playing is experiencing the same problem but with better glasses. I only know it’s working properly with the lenses and twilight glasses.

It’s not much of a consolation but at least there are ways to clear the level just by moving the peasants.


#9

I’ve just made a tweak to Goalkeeper and Ice Soccer so that your hero can always see the ball regardless of your glasses’ range and x-ray-vision abilities. Thanks for debugging this one for me!


#10

I’m having difficulty trying to identify the different peasants. Rather than follow the ball above and below the goal I’ve narrowed it down so each peasant can cover just half of the goal. Thing is, I can’t seem to target individual peasants.

I’ve tried identifying them by name in the command code: friends["Burk"] and array number friends[0] but no luck.

Does the array only work if use the ID’s in a while loop?

Do I have to define friends = [] as well?

Any help would be greatly appreciated. Here’s my code:

 loop:
    friends = self.findNearest(self.findFriends())
    ball = self.findByType("ball")[0]
    if ball.pos.y < 42 and ball.pos.y > 36:
        self.command(friends["Burk"], "move", {'y':ball.pos.y})
    if ball.pos.y < 35 and ball.pos.y > 29:
        self.command(friends["Millicent"], "move", {'y':ball.pos.y})

#11

There’s no need to use friends["Burk"]. Just "Burk" will do.


#13

I still get an error on line 5 and 7 where I make the command:

Error says Hero Placeholder needs something to command

loop:
    friend = self.findNearest(self.findFriends())
    ball = self.findByType("ball")[0]
    if ball.pos.y < 42 and ball.pos.y > 36:
        self.command("Burk", "move", {'x' :15, 'y':ball.pos.y})
    if ball.pos.y < 35 and ball.pos.y > 29:
        self.command("Millicent", "move", {'x': 15, 'y':ball.pos.y})

#14

Hm. I guess the command function doesn’t take names. All right, then use something like this:

Burk = self.findByType("peasant")[0]
Millicent = self.findByType("peasant")[1]
if Burk and Millicent:
    # Do stuff.

#15

Yeah that works! I separated them out to command them individually and gave them a starting position in net to complete the Bonus.