# Complete the paladin rectangle to protect the village.
# This function finds the left-most unit.
def findMostLeft(units):
if len(units) == 0:
return None
mostLeft = units[0]
for unit in units:
if unit.pos.x < mostLeft.pos.x:
mostLeft = unit
return mostLeft
# This function finds the bottom-most unit:
def findMostBottom(units):
if len(units) == 0:
return None
mostBottom = units[0]
for unit in units:
if unit.pos.y < mostBottom.pos.y:
mostBottom = unit
return mostBottom
paladins = hero.findByType("paladin")
# Find the top left paladin with findMostLeft function:
# Find the bottom right paladin with findMostBottom function:
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
# Move to the {X, Y} point from the previous step:
# Continue to shield while the volcano is erupting:
while true:
hero.shield()
What is the issue? The “T” in true should be capitalized. You don’t use the functions defined earlier, which leads to the problem (most likely).
use the functions for this part:
# Find the top left paladin with findMostLeft function:
# Find the bottom right paladin with findMostBottom function:
# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
# Move to the {X, Y} point from the previous step:
Most of the work is already done. All you need to do is use the functions to find the x and y pos for the hero to move to.
You can go to the level editor, find the level, then click on the hero. You can go to programmable and find the source code. You can submit a patch there. I think it’s better if you know how to do it as well.
Danny
ww2_Tanker I looked at the code you did on your other chat thingy (Volcano Fighters HELP) and I saw a mistake in your code(I just did trial and error.) This is what you need to add to the paladins, starting from #Find the top left paladin with findMostLeft function:
paladin1 = findMostLeft(paladins) #Find the bottom right paladin with findMostBottom function:
paladin2 = findMostBottom(paladins)
#Use X coordinate from the top left paladin: #and Y coordinate from the bottom right paladin:
x = paladin1.pos.x
y = paladin2.pos.y #Move to the {X, Y} point from the previous step:
hero.moveXY(x, y) #Continue to shield while the volcano is erupting:
while True:
hero.shield()
So your actual code should be:
#Complete the paladin rectangle to protect the village.
#This function finds the left-most unit.
def findMostLeft(units):
if len(units) == 0:
return None
mostLeft = units[0]
for unit in units:
if unit.pos.x < mostLeft.pos.x:
mostLeft = unit
return mostLeft
#This function finds the bottom-most unit:
def findMostBottom(units):
if len(units) == 0:
return None
mostBottom = units[0]
for unit in units:
if unit.pos.y < mostBottom.pos.y:
mostBottom = unit
return mostBottom
paladins = hero.findByType(“paladin”) #Find the top left paladin with findMostLeft function:
paladin1 = findMostLeft(paladins) #Find the bottom right paladin with findMostBottom function:
paladin2 = findMostBottom(paladins)
#Use X coordinate from the top left paladin: #and Y coordinate from the bottom right paladin:
x = paladin1.pos.x
y = paladin2.pos.y #Move to the {X, Y} point from the previous step:
hero.moveXY(x, y) #Continue to shield while the volcano is erupting:
while True:
hero.shield()