CodeCombat Range Finder Help


#1

I,am stuck at the range finder can you help me please
this is my code

while true do

local enemy1 = "Gort"
local distance1 = self:distanceTo(enemy1)
self:say(distance1)

local enemy2 = "Smasher"
local distance2 = self:distanceTo(enemy2)
self:say(“23.44”)

local friend3 = “Charles”

local enemy4 = "Gorgnub"
end

and i dont now it can you please help me


#2

Did you even try first?

  1. Why did you write self:say("23.44")? Surely there’s a reason for distance2?
  2. Charles is a friend. You do not want to shoot Charles.
  3. Gorgnub is an enemy however. Use what you did for enemy 1 and enemy 2 and base the code for enemy4 off of the prefilled in code.

#3

yes i did and it does not work


#4

Show me your new code


#5

local enemy1 = "Gort"
local distance1 = self:distanceTo(enemy1)
self:say(distance1)

local enemy2 = "Smasher"
local distance2 = self:distanceTo(enemy2)
self:say(“26.00”)
self:say(“23.44”)
local distance = self:distanceTo(enemy)
enemy3 = "Gornub"
local friend3 = “Charles”

local enemy4 = “Gorgnub”

here is the code
_TD_Rodyt


#6

You still did not listen to previous post.

Please follow the instructions:

  1. Why did you hardcode self:say("26.00") & self:say("23.44")? What’s the purpose of defining distance2 if you’re not going to say it? :wink: (Hint)
  2. Gorgnub is an enemy. Again, same as number two, why define enemy4 = "Gorgnub" if you’re never going to use enemy4? If you don’t know what to do with enemy4, look back at what the sample code did for enemy1 and enemy2 and do the same for enemy4.

Also, please note in the future, to format your code in FAQ format. When creating a new post with code in it, highlight the code and press the </> button next to the quotations and print icon.


#7

In the future please format your code according to the FAQ. It helps us better understand your code as we try our best to help you. Also we cannot just give you the code. It makes it easy for you to just get the code, and pass the level without learning anything. Here is the link for our community guidelines.
https://discourse.codecombat.com/faq

Please :heart: this post if it is useful

Cheers :beers: