-- 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.
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