(Python) Backwoods Fork 16/120


#1

No estoy comprendiendo bien el procedimiento que debo realizar al crear la variable y luego usarla en la función checkAndAttack

# Use the checkAndAttack function to make your code easy to read.

# This function has a parameter.
# An parameter is a way of passing information into a function.
def checkAndAttack(target):
    # The 'target' parameter is just a variable!
    # It contains the argument when the function was called.
    if target:
        hero.attack(target)
    hero.moveXY(43, 34)

while True:
    hero.moveXY(58, 52)
    topEnemy = hero.findNearestEnemy()
    # Using the checkAndAttack function with the topEnemy variable.
    checkAndAttack(topEnemy)

    # Move to the bottom X mark.
    hero.moveXY(58, 17)
    # Create a variable named bottomEnemy and find the nearest enemy.
    
    # Use the checkAndAttack function, and include the bottomEnemy variable.
    

Saludos!! :grinning::beers:


#2

Use bottomEnemy=hero.findNearestEnemy()
And call the function Checkandattack using bottomEnemy in the parentheses of checkandattack


#3

gracias por tu ayuda @Chaboi_3000 pude comprender mejor con tu ayuda :grinning:

Tan fácil como crear la variable según lo que decía el comentario y usar esa variable en la función checkAndAttack

# Create a variable named bottomEnemy and find the nearest enemy.
    bottomEnemy=hero.findNearestEnemy()
    # Use the checkAndAttack function, and include the bottomEnemy variable.
    checkAndAttack(bottomEnemy)

Saludos!! :grinning::beers:


#4

Glad it helped! Keep going in your journey in the world of codecombat!