Boulder Woods if/else Problem

What is wrong with this code?

Use isPathClear to move around the randomly positioned boulders.

Automatic pathfinding doesn’t work in Boulder Woods.

loop:
angle = Math.PI / 2 - Math.PI / 16
while angle >= -Math.PI / 2:
targetX = self.pos.x + 5 * Math.cos(angle)
targetY = self.pos.y + 5 * Math.sin(angle)
# Use isPathClear between your current pos and the target.
# If the path is clear, move to the target.
if self.isPathClear(targetX, targetY):
self.move({‘x’: targetX, ‘y’: targetY})
# Otherwise, sweep the angle clockwise a bit.
angle -= Math.PI / 16
else:
self.move({‘x’: targetX, ‘y’: targetY})

It says that there is an “Unexpected Token” on the second-to-last line with the “else:” statement on it. I know that this is a new level so is it me who has done this wrong or developers…? Help please!

You’re using isPathClear wrong. isPathClear takes two arguments, the beginning position (in this case, your hero’s position), and the target position.

Sooo . . . should I do it more like this?

if self.isPathClear({‘x’: targetX, ‘y’: targetY}, {‘x’: self.pos.x, ‘y’: self.pos.y}):

Yes, more like that, but switch the two arguments.

If you’re problem is solved, you can put it in the “solved” category…

Cool! Thanks for the help!

How do I put it in the “solved” section?

I’ve recategorized it for you.
I’m not sure whether regular users can tag their topics as “solved” on their own.
You can try clicking the pencil icon at the right of thread title (near the top of this page) and see if you can change the category.