[SOLVED] Commanding to move (js)

hello everyone,
I am having a problem / don’t understand how to command friendly units to move to some unidentified place (for example: ball.pos).
can someone explain can you command units to move somewhere?
with many thanks,
foxfire :fox_face:

friends = hero.findFriends()
for friend in friends:
    hero.command(friend, move, ball.pos)

if you know javascript, it will be great, because I learn javascript and therefore I don’t know python (which I assume is this code language).

summary: I don’t understand what you wrote in there because it’s in python and I don’t know python.

sorry :frowning:

Python and JS are pretty alike, so the general idea is he same, even though there might be an extra character here and there.

javascript has some elements that python do not have (and vice versa).

if someone could just explain to me that method, I will be grateful.
foxfire :fox_face:

Hi foxfire,

If you want to move one of your friends:

var friend = hero.findNearestFriend();
hero.command(friend, "move", ball.pos)

If you want to move a group of friends:

var friends = hero.findFriends();
for (var i = 0; i < friends.length; i++) {
   var friend = friends[i];
   hero.command(friend, "move", ball.pos);


1 Like

Wow. JS for-loops look much harder than Python.

they are! (or at least i think they are)

hey @jka2706,
thank you so much for your answer!
I ended up writing really complicated code, and you just came and boom!
everything so simple!
i also remember that you helped me with the arrays, so double thanks :heart:

Hi foxfire,

You’re very welcome.

That’s cool that you wrote your own code to try to solve it a different way. As I keep on with coding I find it useful to look at other people’s code (after I’ve solved something). There’s usually someone who’s done it a really clever way, so I learn things by doing it myself, and I learn things from how they’ve done it as well.

Happy coding :smile:.


yea ikr especially since they don’t show the blue/white spaces for JS

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.