This is Summit’s Gate level in Cloudrip Mountain and I am receiving the error in the screenshot for Line 4: friends = hero.findFriends()
Is there something wrong with this code or is it a bug?
*Note: I received the same error when writing: paladins = hero.findByType("paladin")
I don’t think you need to @ the staff yet. Aya might have something wrong with their code, and @-ing Chaboi is better than @-ing the staff. The staff are very busy so please take that out for now.
Have you put in what they suggested? I had that error for distance = hero.findNearestDistance I replaced it with hero.findNearestDistance. That worked. (I’m not sure if I had to add and delete a few things from my code for it to work or not, but if you need to, you could probably figure out how)
I have my twilight glasses on, those red ones. What i did is that i wrote “friends” and then the whole line appeared as a suggestion, so I clicked “enter”, and then when I ran it, it gave me this error.
Yes, this is one of the most interesting user bugs ( errors) i have ever encountered.(The above code has plenty of other errors also ). Please don’t summon Bryukh and other really busy people.
lets run trough your code:
3 while True:
4 friends = hero.findFriends()
5 for friend in friends:
6 if friend.type == "archer":
7 catapults = hero.findByType("catapult")
8 if catapults:
# if catapults will be always True in CoCo
# the right check is if len(catapults) > 0:
# but you really don't need this line so delete it
9 for catapult in catapults:
10 hero.command(friend, "attack", catapult)
# this is more strategy error: You archer will fist go to the
# catapult 1 then catapult 2 and will be dead very quickly
11 elif friend == "soldier":
12 enemy = hero.findNearestEnemy()
# usually it's enemy = friend.findNearestEnemy()
# then check if enemy:
13 hero.command(friend, "attack", enemy)
14 elif friend == "paladin":
# and then the most unusual, strange and fascinating error
15 hero = paladin.findByType("hero")
16 hero.command(friend, "cast","heal", hero)
hero = paladin.findByType(“hero”)
There is no type “hero” ( Anya’s type is “captain”)
The paladin have no method findByType so paladin.findByType(“doesn’t matter the string you put here”)
will return undefined
so you effectively kill your hero making it undefined
first line of the the second iteration of the loop is
friends = hero.findFriends()
but the program reads it as friends = undefined.findFriends()
and you have your error message
So what I understand is that when the hero dies it becomes undefined which creates this error. Right?
I’m going to fix my code. Thanks a lot @stormbringer