# Library Tactician Problems

I am having problems with Library Tactician, I have done exactly what they told me to do (except the part that says “-- Create a variable containing your archers.” which I don’t understand because that variable already exists…) for some reason my soldiers still cannot survive in spite of following their instructions to the letter (along with trying various things of my own) here is my code;

``````-- Hushbaum has been ambushed by ogres!
-- She is busy healing her soldiers, you should command them to fight!
-- The ogres will send more troops if they think they can get to Hushbaum or your archers, so keep them inside the circle!

-- Soldiers spread out in a circle and defend.
local function commandSoldier(soldier, soldierIndex, numSoldiers)
local angle = Math.PI * 2 * soldierIndex / numSoldiers
local defendPos = {"x"= 41, "y"= 40}
defendPos.x = defendPos.x + 10 * Math.cos(angle)
defendPos.y = defendPos.y + 10 * Math.sin(angle)
self:command(soldier, "defend", defendPos)
end

-- Find the strongest target (most health)
-- This function returns something! When you call the function, you will get some value back.
local function findStrongestTarget()
local mostHealth = 0
local bestTarget = nil
local enemies = self:findEnemies()
-- Figure out which enemy has the most health, and set bestTarget to be that enemy.
for _, enemy in pairs(enemies) do
if not bestTarget or enemy.health > mostHealth then
bestTarget = enemy
mostHealth = bestTarget.health
end
end
-- Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15 then
return bestTarget
else
return nil
end
end

-- If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
local function commandArcher(archer)
local nearest = archer:findNearest(archer:findEnemies())
if archerTarget then
self:command(archer, "attack", archerTarget)
elseif nearest then
self:command(archer, "attack", nearest)
end
end

local archerTarget = nil
local archers = self:findByType("archer")
local soldiers = self:findByType("soldier")
-- Create a variable containing your archers.

loop
-- If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget then
archerTarget = findStrongestTarget()
end
if archerTarget then
if archerTarget.health <= 0 then
-- Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()
end
end
for i, soldier in pairs(soldiers) do
commandSoldier(soldier, i, #soldiers)
end

-- use commandArcher() to command your archers
for _, archer in pairs(archers) do
commandArcher(archer)
end
end
``````

Solved…Had to re-write my code in Javascript(Python didn’t work either, I didn’t try coffee script)…apparently the lua interpreter is too slow to run the code.

@deeredman1991 I had to change the source code and then submit about 100 times