Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

findNearestFriend function not noticed?


#1

First, I’d like to ask if I’m using the correct term by calling “findNearestFriend” a “function” - I feel as if I’m using it wrongly.

Secondly, for my main issue, please have a look below

I’m programming in LUA btw.

it says I I don’t have the “findFriends” skill, but when I look at my list of skill, I’ve found I already have the skill granted by my hero himself. This is the first time I’ve come across “findNearestFriend” - it didn’t as ask me to buy any specific item before I went to this level either. Is there a bug to this?


#2

It’s only for this level.

About your error:
local friend = self:findNearestFriend()


#3

I don’t think there is a findNearestFriend function. You will need to use
two functions, findNearest and findFriends.


#4

This function exist for the current level. Because players (usually) don’t have “findFriends” yet.


#5

Well that’s strange because the “findNearestFriend()” function was already written down by the computer itself not me. Hence the code should have existed


#6

may someone help me it still does not work regardless


#7

what’s the difference? That’s not even my question!


#8

I answered you. Please, look my previous answers.


#9

it still does not work, it just returns a nul


#10

Could you post your actual code?


#11

Ah nevermind, the one that you see on the picture was my actual code except more organized. After hours of fiddling around, I manage to find the cause of the problem.

It was no more then a bug, I had to exit the level, de-equip my new pair of glass and equip them again before entering the level. The code that I remains unchanged and yet works. This is something the developer of codecombat should take a look into as it is really frustrating.


#12

just in case you are wondering here is my code:

while true do
local friend = self:findNearestFriend()
local enemy = self:findNearestEnemy()
if friend and enemy then
self.say("To battle, " + friend.id + “!”)
self.say(“Go Away,” + enemy.id + “!”)
–# Now find the nearest enemy and tell them to go away.
end
end

the use of “else” doesn’t work because I don’t have a for loop equipped yet


#13

If you are still having problems with that code, please format it according to the FAQ. It helps us be able to understand your code as we try to help you.
https://discourse.codecombat.com/faq