Boulder Woods if/else Problem


#1

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!


#2

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


#3

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

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


#4

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


#5

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


#6

Cool! Thanks for the help!


#7

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


#8

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.