Lua combat error


#1

I was trying to go back through the levels and try the lua programing. It pops up with an error saying enemy not found please use enemy = hero:findNearestEnemy(). here’s my code:

while true do
enemy = hero:findNearestEnemy()
hero:attack(enemy)
end

Anyone know why its telling me this error if i have the code it tells me to use?


#2

Try using something like:
if enemy
or
while enemy


#3

Ya i tryed that but then it either wont work or only kill one then stop


#4

What level are you playing?
What gear are you using?
Has this ever happened more than once?


#5

I think that the end is making it stop the loop so it only attacks once.


#6

I just started using lua and i’m replaying the beginning. no this has never happened before. i’m using the some new gear i got and some old ones.


#7

I removed the end but it tells me to fix my code and that i need end.


#8

So is it Dungeon, Forest, Desert, Mountian, or Glacier?
What name is the Level?
The reason I am Asking is to make sure that code combat is working correctly.
So could you send me the link?


#9

I’m in the dungeon on the level mayhem of munchkins.
link to the level: https://codecombat.com/play/level/a-mayhem-of-munchkins


#10

It’s not an enemy its a local enemy.

write instead

while true do
    local enemy = hero:findNearestEnemy()
    hero:attack(enemy)
end

#11

ok thanks. ill try that and see how it works.


#12

now its telling me it received null and asked if hero should always attack and use if. i tried but it wouldn’t work. is there a way i should type an if statement in lua that i don’t know?
(never mind. it works fine now) (thanks)