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

Store position as a variable

In the level “logical circles” in the backwoods forest map (on the northeast part of the map). I am tasked with getting the character to move up/down or left/right based on the criteria provided. I tried storing the hard coordinates for the positions marked on the map as variables in order to reduce the amount of coding needed.

u = 30, 33
d = 30, 15

secretD = secretA and secretB and secretC
if secretD:

I get the error as follows:
Line #: ArguementError: moveXY takes only undefined argument. should have type number, but got array. moveXY requires 2 numbers as arguments, x and y.

If I’m interpreting this correctly it’s saying that it’s reading the variable as a two number array instead of the first number for X and the second number for Y. Is that correct?

Is there a way to rewrite the code to keep it concise while still following this train of thought by either calling the variable in a different way or storing the coordinates in a slightly different manner?

Try this:

u = {"x": 30, "y": 33}

Edit: Nevermind, it won’t work for moveXY. This is covered in later levels but only for the move method.

you could still utilize it by passing u.x and u.y as arguments to the moveXY function though.

1 Like

The move XY() requires an x and y variable.
I’ll demo what the two above would look like together.

u = {x: 30, y: 33}
hero.moveXY(u.x, u.y)

For this level, you can simplify a few by using a variable for the x and y to minimize some repetition.

x = 30
y = 24
hero.moveXY(x, 33)
hero.moveXY(20, y)

Later you will learn about functions that could eliminate the sections that repeat.