Help on OgreEncampment

if enemy then
    local enemy = self:findNearestEnemy()
    self:attack(enemy)
    self:attack(enemy)
else
    self:attack("Chest")
end

This is the code for Ogre Encampment. It wont work. the problem is that every time im delete a line whos empty, it wont go away. thats the error.btw its lua

Please format your code according to the FAQ. And also what programming language are you using? Looks to me like python. If so, you should not have local enemy. And also, you need a loop.
In python:

local enemy = self.findNearestEnemy()
self:attack(enemy)
self:attack(enemy)
else
self.attack("Chest")

Would turn into:

enemy = findNearestEnemy()
if enemy:
       self.attack(enemy)
       self.attack(enemy)
else:
   self.attack("Chest")

As Bashir says, the language is Lua.

As Luke says, Bashir, please read the FAQ and learn how to format your code properly. I’ve done it for your this time, but do so yourself in the future.

First of all, you should probably place this code in a loop, so that it will run over and over again. Second, you check for enemy, then define it. This is quite irregular. Move the definition of enemy before the if-statement.

1 Like

There some more to do (Lua) - my solution:

  1. “if enemy” only works, if the variable “enemy” is filled, here with self:findNearestEnemy()
  2. You need a loop to repeat attacking suddenly sporning enemies.
loop

   if enemy=self:findNearestEnemy()
        then self:attack(enemy)
   end
   self:attack("Chest")
    
end

Thx for help!
It worked man.

1 Like