Greed: Peon.getItems array is always empty

There are items on the map and close by this peon

var peons = base.getByType(‘peon’);
var peon = peons[0];
var i = peon.getItems();

i variable is always empty

An idea : maybe you want to use : peon.getNearest(items).
It will return the nearest item of the peon.
Because for me the getitems is only applicable to this.
It returns an array of all the items in the level. Like :

var items = base.getItems();

Then you can do :
i = peon.getNearest(items)

@rramon That looks like a bug. Can you check for me if it is actually empty (try to use the result in your code), or is the hover debugger just buggy here?

I would try the base.getItems() instead. The peon may not have privileges to get all the items themselves, and the items returned will be the same either way if it does.

@Ed_Reynolds Thanks! Ill just use that.


var peon = peons[peonIndex];
var i = peon.getItems();
var item = base.getNearest(i);
if (item)
base.command(peon, ‘move’, item.pos);

Seems to be empty. The peon does not move.

@Vettax Thanks, I have decided to go with that.

When I do var items = base.getItems();items is undefined.
Can someone fix this?

I mean, take a look at this.

Until the first coin spawns, there will be no first item. You need to check items.length >= 0 before attempting to use them.

1 Like

I think Bellardia is right. Your base’s code has been replaced by an empty function after the first frame, when it tried to access an item on frame 0 when there are none. Now, the hover debugger should probably indicate that your code has stopped running after an error rather than pretend to show variable state from a frame when that code didn’t exist.

I’ll track that issue over here.