Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Codecombat Savren Road

I have a problem with my code, I’m not sure what is wrong.
‘’’
while True:
# If there’s an enemy, attack.
enemy = hero.findNearestEnemy()
hero.posx = x
hero.posy = y
x = x+3
y = y+3
if enemy:
hero.attack(enemy)
pass
else:
hero.moveXY(x, y)
pass
# Else, keep moving up and to the right.
pass
‘’’
thanks

while True:
    # If there's an enemy, attack.
    enemy = hero.findNearestEnemy()
    hero.posx = x
    hero.posy = y
    x = x+3
    y = y+3
    if enemy:
        hero.attack(enemy)
        pass
    else:
        hero.moveXY(x, y)
        pass
    # Else, keep moving up and to the right. 
    pass

Looks like the x and y variables are not being assigned correctly.

x = hero.pos.x #variable on left and value on right

That was the problem, thanks. But shouldn’t the order not matter since there is a equal sign?

it may have been that you needed to assign a value to x or find out what x is in order for it to work
I could be wrong though :smile: :+1:

The one main rule for Python variables is which side of the = sign.

variable_name = "value being assigned"

Some other languages you have to declare the variable and sometimes it’s type before you can even us it.

JavaScript

var variable_name = "value being assigned"