Codecombat - Double Gaps

Heres my code, I’m don’t quite understand the something part

# Get the hero and the peasant to the south.

# The function move your hero down along the center line.
def moveDownCenter():
    x = 40
    y = hero.pos.y - 12
    hero.moveXY(x, y)

# The function build a fence on the right of something.
def buildRightOf(something):
    # buildXY a "fence" 20 meters to something's right.
    hero.buildXY("fence", something.x+20, something.y)

# The function build a fence on the left of something.
def buildLeftOf(something):
    # buildXY a "fence" 20 meters to something's left.
    hero.buildXY("fence", something.x-20, something.y)

while True:
    ogre = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    if ogre:
    if coin:

with the something.x / something.y
have you tried putting something.pos.x instead?

1 Like

@RiceRunner is correct.

To explain what is happening with the function. In this case something is a variable that is only used within this function. It can have any name, but needs to be used throughout the function consistently

def buildRightOf(variable_for_function):
    # buildXY a "fence" 20 meters to something's right.
    hero.buildXY("fence", variable_for_function.pos.x + 20, variable_for_function.pos.y)

When you call the function in your main code, you will add the variable that you want to pass into the function.

ogre = hero.findNearestEnemy()

Essentially, something = ogre in the function and takes the attributes and properties of the variable passed in to evaluate inside the function. What makes functions helpful, is you can pass any variable into the function which is why it will have it’s own local variable name.

coin = hero.findNearestItem()
buildLeftOf(coin) # now it will build left of the coin instead of ogre