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

Lua combat error


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()

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


Try using something like:
if enemy
while enemy


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


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


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


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.


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


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?


I’m in the dungeon on the level mayhem of munchkins.
link to the level:


It’s not an enemy its a local enemy.

write instead

while true do
    local enemy = hero:findNearestEnemy()


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


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)