Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Examples for move() method (python)


Hi there,

I’m currently on the level “zoo keeper” and I’m having a tough time getting my head around using objects other than direct x and y values in the move() action. I’ve used it successfully in examples like:

    self.move({"x": 25, "y": 25})

But I haven’t found an example / a way to understand how to move the the position given by an object (as an example here, to the x and y position given by the “points” variable that I’m looping through).

Can someone post an example of using the move() with other object values than simple coordinates? That would be really helpful :smile:

Edit: the code I wanted to write was:

self.command(friend, "move", points)

but that’s not working…



I’ve now passed the level, but wanted to give feedback on some confusion I had doing it.

The syntactically correct code I was looking for in my example above would have been:

 self.command(friend, "move", { "x" : point.x, "y": point.y})

It would still help me if someone could explain / give some more examples using this move method.

The code that actually made the level work was, however:

 self.command(friend, "move", point)

The other method only ever sent one soldier to the place and the soldier didn’t attack.

So I guess I have a couple of questions:

  • Can the command method work with both a move and a moveXY approach? If so, could that be documented / an example given?
  • Why didn’t my first example work?

Thanks for any help!


Technically both examples should work, but because point is already an object with an x and a y property values it’s easier to use point. Why the first example doesn’t work I have no clue.

moveXY behaves differently, as explained in the first set of mountain levels. I doubt you can call moveXY on a minion, and you probably wouldn’t want to (at least in future situations), because moveXY moves all the way.

Also, there is a custom Vector class built in; while there are a lot of new methods, the most basic usage is to use it like Vector(x, y):

pos = Vector(9, 16)
this.move(Vector(25, 9))
this.command(minion, "move", Vector(16, 25))

It’s pretty advanced though, and its API is only shown in Programming Book 5.


The “first one” doesn’t work because it is “points” not “point”, “points” is probably an array of position (pos) objects ("point"s) and not a pos object.