Hello, I stopped with CC for a while because I found Glacier frustrating, and now that I’m trying again I’m running into typical CC problems like I used to have with Mountain.

I’ve tried to replicate code from Skating Away and did so successfully to reach any potion:

``````# Catch the potion by standing near it before it lands.
# DO NOT LET THE POTION LAND ON THE GROUND!

# Say anything within 10m of Omarn for him to throw a potion.
# Catch the potion by standing near it before it lands.
# DO NOT LET THE POTION LAND ON THE GROUND!
# hello
while True:
potion = hero.findFriendlyMissiles()
firetraps = hero.findHazards()
# Remember that a Fire Trap will trigger if you move closer than 3 meters!
omarn = hero.findByType("potion-master")
if potion:
dest = potion.targetPos
# Go get the potion.
goal = Vector.subtract(dest, hero.pos)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, 5)
trap = hero.findNearest(firetraps)
distance = hero.distanceTo(trap)
if distance < 5:
myVector = Vector.subtract(hero.pos, trap.pos)
myVector = Vector.normalize(myVector)
myVector = Vector.multiply(myVector, 5)
hero.move(moveToPos)
``````

but then what I get stuck on, is that I need to do something with the Else statement and everything I can conceive of goes wrong there.

This is the standard code provided by the level maker:

``````else:
if omarn and hero.distanceTo(omarn) > 10:
# Move back to Omarn.
hero.moveXY(7, 34)
pass
else:
hero.say("Hup, hup!")
``````

But in this case the hero just blindly runs into the trap, so I’m supposing that’s where we need to create a vector as well, to turn back to the mage’s position.
And that’s where I just spent more than half a hour just running into infuriating problems like ‘‘Ran out of time’’ error.
Whatever I do, the program constantly prioritizes this else: code and no longer cares about potions (in other words, it never reads the if potion: part again). Even if there’s no errors, all the main character does is constantly want to go to the destination point where Omarn is or whatever other point you want him/her to go to. Also, in this case Omarn does nothing at all. I have run into this type of error several times in my CC journey where if and else statements are not doing what I want at all. Here’s the code:

``````else:
goalPoint = Vector(7, 34)
goal = Vector.subtract(goalPoint, hero.pos)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, 5)
trap = hero.findNearest(firetraps)
distance = hero.distanceTo(trap)
if distance < 5:
myVector = Vector.subtract(hero.pos, trap.pos)
myVector = Vector.normalize(myVector)
myVector = Vector.multiply(myVector, 5)
hero.move(moveToPos)
``````  Alternative version where I keep an original line of code intact, but then I ‘‘run out of time’’:

`````` else:
if omarn and hero.distanceTo(omarn) > 10:
# Move back to Omarn.
goalPoint = Vector(7, 34)
goal = Vector.subtract(goalPoint, hero.pos)
goal = Vector.normalize(goal)
goal = Vector.multiply(goal, 5)
trap = hero.findNearest(firetraps)
distance = hero.distanceTo(trap)
if distance < 5:
myVector = Vector.subtract(hero.pos, trap.pos)
myVector = Vector.normalize(myVector)
myVector = Vector.multiply(myVector, 5)
hero.move(moveToPos)
``````

This is where nothing happens: I wonder if there’s anything to make the program exit this else statement and go back to the original choice between if and else. But ‘‘break’’ only works with loops.

You should say “Hup hup” when your distance to Omarn is less than 10. Otherwise, he will not throw the potion. And if your distance to Omarn is greater than 10, you should go to the X mark using your Vectors.

3 Likes

This works, spasiba.

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.