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

The If-Stravaganza level help? (LUA)


#1

Please take a look at the picture below:

This what is the code that I wrote for the if-statement level. I’m 100% sure that I’ve written the code correctly and even searched up for the solution, in which I got similar to this. Though the code does not work when I execute it, instead it returns me with an error message saying “this.findNearestEnemy is not a function” as highlighted on line 4 of my code.

Does anyone know the solution to this? I’ve tried everything, thanks


#2

Do you have the right glasses on?


#3

try : instead of . and try to cleave, because you have a warrior

 local enemy = hero:findNearestEnemy()
     if enemy and self:isReady("cleave") then self:cleave(enemy)
     else 
        if enemy then self:attack(enemy) 
        else
        end
    end

#4

Yeah your prediction was correct, I didn’t have the right glasses on >_<

But it’s strange since the glass that I’m using in the screenshot had the “findNearestEnemy” function and is more advanced then the beginner glass - which only had one function, the “findNearestEnemy”. Yet I had to equip that specific one in order for it to work. Could this be an unnoticed bug?


#5

it says i cant use ‘local’ or ‘enemy’


#6

Post your code. Make sure you are using the right language, local is only for LUA, use var for JS and nothing for Python.

Lua: local enemy =

Js: var enemy =

Python: enemy =


#7

I still cant get it to work can you help me?


#8

Please post your code so we can assist you. Remember to use the </> button so it formats properly.


#9

while True:
enemy = hero.findNearestEnemy()
hero.attack(enemy)
hero.attack(enemy)

I am so confused on this level


#10

You started the level in LUA? https://codecombat.com/play/level/if-stravaganza?codeLanguage=lua ?
You code can be similar to:

while true do
    local target = hero:functionToFindTheEnemy()
    if target then
        hero:attackTheEnemy(target )
    end
end

#11

it wont let me do local


#12

if you click the link:
image
image click restart
and then write you code:
image
I suppose you really want LUA


#13

can’t click the link


#14

never mind I got the link to work


#15

I don’t know what to do after that


#16

Just do what the comments say, and if you’re stuck, try reading the hints