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")
@chaboi_3000 (20 chars)(20 chars)
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)
maybe u dont have glasses on I lose vision if I have my glasses or not
If u thought that was a pun it was not
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.
try refreshing or ask chaboii
I just tried refreshing, nothing. @Chaboi_3000 can you please help?
plz dont @ chaboii he/she is asleep as in tokyo he would be asleep by now
Oh I’m sorry, should’ve taken care of that
I think it is a bug with coco try asking @Bryukh
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
your program can be shortened to
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
Nice! Yeah, I’ve spent at least 5 mins to notice that they reassigned
@Aya it’s a bad idea to reassign
hero global variable
So how can I tell my paladins to heal me, like to find me?
why you need to search the hero if you already have the reference to the hero? O_o
I didn’t understand, what is my reference to the hero, is it in the code?
What do you think is the global variable
Does it has health or speed? maybe IT’S the unit what you are searching.
Alright, I just got it, I fixed it and it worked. I should’ve thought about that . Thanks a lot for your help