Volcano Fighters SOS HELP SOS HELP

When i run my code it says

here is my code:

# Complete the paladin rectangle to protect the village.

paladins = hero.findByType("paladin")



# 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



# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
    if len(units) == 0:
        return None
    mostTop = units[0]
    units = findMostLeft(units) 
    for unit in units:
        if unit.pos.y > mostTop.pos.y:
            mostTop = unit
    topLeft = mostTop
    return topLeft
    
    
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
    if len(units) == 0:
        return None
    mostRight = units[0]
    findMostBottom(units)
    for unit in units:
        if unit.pos.x > mostRight.pos.x:
            mostRight = unit
    bottomRight = mostRight
    return bottomRight

# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
if paladins:
    coordX = findTopLeft(paladins).pos.x
    coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while true:
    hero.shield()

@AnSeDra please help

Check your capitalition here.

Here get the x coordonate of the unit that this function returns.

And do not forget to change units to another array at the use of the function. (Where I quoted it should remain units)

Here get the y coordonate of the unit that this function returns.

And do not forget to change units to another array at the use of the function. (Where I quoted it should remain units)

Andrei

2 Likes

help plz my code:

# Complete the paladin rectangle to protect the village.

paladins = hero.findByType("paladin")



# 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



# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
    if len(units) == 0:
        return None
    mostTop = units[0]
    units = findMostLeft(units) 
    for unit in units:
        if unit.pos.y > mostTop.pos.y:
            mostTop = unit
    topLeft = mostTop
    return topLeft
    
    
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
    if len(units) == 0:
        return None
    mostRight = units[0]
    findMostBottom(units)
    for unit in units:
        if unit.pos.x > mostRight.pos.x:
            mostRight = unit
    bottomRight = mostRight
    return bottomRight

# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
if paladins:
    coordX = findTopLeft(paladins).pos.x
    coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while true:
    hero.shield()

there is an error (dosent say what line) that says: "TypeError: Need an object what is wrong @AnSeDra @dedreous @Deadpool198 are any of u able to help?

Take a closer look at this comment:

There is no need to create a new function (findTopLeft), as you’ve already done that work. Instead, define a new variable as equal to the existing function.

Same goes for ‘findBottomRight’.

Delete the ‘if paladins:’ line, then correct your two coord statements.

2 Likes

so do i just deleat all of that part? also what do i do with the move then? @dedreous

As I stated, delete only the line with ‘if paladins:’.Then rest is just fixing and tidying up your code.

i did that i deleated the if palidins: line and there is an error saying try hero.pos

now its saying type error: need an object

here is current code:

# Complete the paladin rectangle to protect the village.

paladins = hero.findByType("paladin")



# 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



# Find the top left paladin with findMostLeft function:
def findTopLeft(units):
    if len(units) == 0:
        return None
    mostTop = units[0]
    units = findMostLeft(units) 
    for unit in units:
        if unit.pos.y > mostTop.pos.y:
            mostTop = unit
    topLeft = mostTop
    return topLeft
    
    
# Find the bottom right paladin with findMostBottom function:
def findBottomRight(units):
    if len(units) == 0:
        return None
    mostRight = units[0]
    findMostBottom(units)
    for unit in units:
        if unit.pos.x > mostRight.pos.x:
            mostRight = unit
    bottomRight = mostRight
    return bottomRight

# Use X coordinate from the top left paladin:
# and Y coordinate from the bottom right paladin:
coordX = findTopLeft(paladins).pos.x
coordY = findBottomRight(paladins).pos.y
# Move to the {X, Y} point from the previous step:
hero.moveXY(coordX, coordY)
# Continue to shield while the volcano is erupting:
while True:
    hero.shield()

Ok…perhaps I was not quite clear. Let’s start from the top.

Delete this entire block:

Replace that block with a line that defines a new variable that is equal to ‘findMostLeft()’

Then, repost your code and we’ll continue.

1 Like

can you give me an example of what the variable should look like @dedreous

is anyone able to help me with the variable? @AnSeDra

Here’s an example from the block you should be deleting:

topLeft is the variable
= mostTop is the definition

1 Like

so what im understanding is that this is not needed at all. correct? but why did u say that i need to deleat this then?

im kinda confused on this right now. @dedreous

I said to delete it, because it is not needed, and is incorrect, if you follow the directions in the comment:

# Find the top left paladin with findMostLeft function:

Note that the comment does not say to create a new function, which is what you did, but to use the existing function to find the top left paladin.

Therefore. Delete that entire block and replace it with a new variable, defined as equals findMostLeft().

1 Like

how do i make a new variable what would it look like?

As I mention earlier:

You created a variable called topLeft and defined it as equals ‘mostTop’…that is how you create a variable and how it would look. .

3 Likes