Any one could help?how can I get the level Lurkers?


#1
-- findEnemies returns a list of all your enemies.
-- Only attack shamans. Don't attack yaks!

local enemies = self:findEnemies()
local enemyIndex = 1

-- Wrap this section in a while loop to iterate over all enemies.
local enemy = enemies[enemyIndex]
if enemy.type == 'shaman' then
    while enemy.health > 0 do
        self:attack(enemy)
    end
end

I use the LUA.but it is no error show me and no action in the game.
HELP. please.


#2

I don’t read LUA, but it doesn’t appear that you increment enemyIndex.


#3

You also do not loop over all enemies. Your while-loop will ensure that this specific enemy will be dead, but all others are ignored.


#6

if you can give me some more information I will apperciate.


#7

I don’t know how to make ensure specific is locked by my hero in LUA.
thank you ~


#8

thanks for your help,I increment the enemyIndex but it nothing happen still.


#9

What is your current code?


#10

I have no experience with LUA, however I read a little up on it and this is what I came up with.
Give it a try:
The problem you are having is you only check the enemy at index 1. Thus any other enemy is ignored. Without a loop, you either never update your list or iterate over it. I removed the index because I think it is un-needed, but I may be wrong. The while loop should iterate through the list one at a time.

-- findEnemies returns a list of all your enemies.
    
local enemies = self:findEnemies()

-- Wrap this section in a while loop to iterate over all enemies.
-- Only attack shamans. Don't attack yaks!

-- Something is missing here, fill it in (Hint: Declare variables)
-- Something is missing here, fill it in (Hint: Assign variables)
while enemies[i] do
   if enemy.type == 'shaman' then
      self:attack(enemies[i])
   end
   -- Something is missing here, fill it in (Hint: must iterate)
end