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

Using this.moveXY


Okay, so I am trying to increment the X parameter variable so I thus can gradually move to the right if there aren’t any enemies around. And this is where I am at so far," // move little by litte and check if an enemy exist
var x = this.moveXY(x,y).x;
var y = this.moveXY.y;
this.moveXY(x+5, y); ."


Here’s an example in javascript:
this.moveXY(this.pos.x + 10,this.pos.y);


To both of you, please format your code according to the discourse FAQ.


How do we format our code?


Okay, so I am confused as to why the code within the parenthesis of “this.moveXY.” works. I thought inside that parenthesis you could only place a number according to either the x parameter or the y parameter. The code acquired what I had wanted, but I just don’t completely understand why it works.


for some reason it’s not letting me post another forum on a separate issue I have it’s giving me 403 forbidden so i’ll just post it here. So i’ve literally just copied the code from the heroes is path clear and I receive the error Line 10: tmp8[tmp9] is not a function. My code looks like this
. . .
var item = this.findNearest(this.findItems());
if (item && this.isPathClear(this.pos, item.pos)) {
else { this.move({x: this.pos.x, y: this.pos.y +5});
. . .


Do this:

this.move({“x”: this.pos.x,“y”: this.pos.y + 5});

That is how I do it.


this.pos.x is the hero’s position’s x coordinate, which is a number, so it is a valid argument (value being passed in) for moveXY. this.pos.x + 10 is that number plus 10.

moveXY() takes two numbers as arguments, and
move() uses a position vector such as
item.pos, {x: this.pos.x, y: this.pos.y +5} or Vector(84,32)

To check if the code in your post is formatted properly, see the preview. There’s even a preview button on mobile devices. Indentation is important for readability and sometimes syntax as well.

  // You should put three backticks at the top
  // and three at the bottom for multiline code

  // Use one backtick on each side for inline

@gat and @baomatai you format your code by putting two or three of these:` around them like this:

code goes here

Ah, I see, you have to put three on top and two on the bottom. Thanks for the reminder! `