Greed how to refer to peasants

This might be a noob question, but in greed, how do I separate 1 peasant from another? E.G when I spawn 2, one of them follows the other. Is there a this.getByName as opposed to a this.getByType?

And also, like there was a greed tournament, will there be a tournament like this in any other game?

this.getByType('peasant') will return an array of peasants. You can distinguish between them by their position in the array - if you say var peasants = this.getByType('peasant'), then peasants[0] is the first peasant spawned and peasants[1] is the second.

You can command each peasant individually by iterating over peasants with a for loop. For example:

var items = base.getItems();
var peasants = base.getByType('peasant');
for (var peasantIndex = 0; peasantIndex < peasants.length; peasantIndex++) {
    var peasant = peasants[peasantIndex];
    var item = peasant.getNearest(items);
    if (item)
        base.command(peasant, 'move', item.pos);
}

Which I believe is part of the default code in Greed. This code will tell each peasant to move toward the item closest to them. If you spawn two peasants close together, they will move toward the same item, since the same item will be closer to them than any other item.

As for your second question, there already is another tournament going on, this time for Criss-Cross.

1 Like

Will there be another tournament seeing as this one is almost over? And how do I get the x-coord of my peasant?
Also thank you for your reply.

peasant.pos.x is the x-coordinate. We haven’t exactly decided how the next tournament will work. We want to hold one for Sky Span, but we also want to feature the new synchronous PVP we’re working on (in addition to the async PVP), and there are a few things left to be figured out there.

When would that occur? Cool!

Whenever we get all the synchronous PVP quirks hammered out. There will be a gap in between the Criss-Cross tournament ending and the Sky Span tournament starting.

I couldn’t figure out what base.in this code does. Is this a useful method?

Please do not revive dead threads. This thread is over a year old.