[Solved]Possible to pass entity reference(s) from lua to js?

I’m attempting a little tweak to allow selection of multiple entities (renewable resource nodes) for transplant. The idea is to drag a selection box and have the applicable selected entities pop to the cursor in turn as though they were individually selected and the “Move Item” button was clicked.

The entity selection is done in lua, and I have a working function that results in a table containing only transplantable entities. Here’s the contents of an example table:

 key                  value
------       ------------------------
259208       (259208 Wild silkweed)
188985       (188985 Berry Bush)
258902       (258902 Wild silkweed)
186544       (186544 Berry Bush)
259055       (259055 Wild silkweed)

I think I understand how to return the information to the js, but I have no idea in what form I need to return it such that it’s usable or can be transformed into something usable. The context in which I’ll need to use it is eg.

placeItem: function(item) {
   this._placeItemOrItemType('item', 'placeItem', item);
},

Any input would be appreciated.

1 Like

IIRC, return it in a call handler using :resolve, return a normal lua table containing the entities. In the :done (or :success, can’t remember right now which one SH uses) part of the JS promise, you’ll get the table as list of entities (or entity references). You might only have limited, or no, access to the entity in JavaScript though.

Thanks. Each value in the resulting object represents the same data item would represent if placeItem() were called by selecting the relevant entity and clicking Move Item.

The rest of the process is going to be a bit more complicated than I initially realized, but at least now I’m almost certain I can make this work. Accidentally realizing there is a way to log from the js makes things much easier… :flushed: