Goalkeeper level advise

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

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]

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

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

What kind of glasses are you using?

hardened steel glass

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

but i can see friends but not enemies nor the ball

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.

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!

1 Like

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:

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

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

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

Error says Hero Placeholder needs something to command

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

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.
1 Like

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

can someone help me there is some sort of error and i can’t fix it
here is my code

# Command the peasants to prevent the ogres from scoring.
# The fireball is type "ball".
while True:
    friends = hero.findFriends()
    if friends:
        hero.command(friend, "move", {'x':17,'y':30})
        hero.command(friend, "move", {'x':17,'y':43})

this is the errorgsrzgd

What do you want to do here?


I want to keep on moving the peasants up and down to block the goal

But where did you said who friend is?


what do you mean???