Found an expression But expected a Statement: While


#1

Hi,
I program on LUA
In the level of “a mayhem of munchkins” i wrote this code :

loop
    local enemy=self:findNearestEnemy 
    self : attack (enemy)
end

But it tells me "Found an expression But expected a Statement: While"
Please Guys Help me !!
Thank you :smile:


#2

maybe check the existence of enemy by

if enemy:

Also… format your code in radiant, harmonious formatting so everyone can easily read it as per FAQs

Cheers


#3

Hello, Safouene, and welcome. Please read the FAQ prior to your next post, so that you learn how to format our code properly. I’ve done it for you this it, but do so yourself in the future.

findNearestEnemy is a method. It requires a pair of parentheses to call properly. Also, I don’t think that you are allowed spaces between self, the colon, and the input argument.