Page 1 of 1

[Not Implemented] LuaControl.insert but don't insert modules

Posted: Sun Aug 13, 2017 8:55 am
by Mooncat
Original title: LuaControl.insert, but don't insert to module inventory
But it won't work.

---------

Request:
Either add an additional parameter in LuaControl.insert or make a new function to let us insert items into entity while ensuring the items won't go to the module inventory.
Also the corresponding LuaControl.can_insert parameter or function.

Currently, LuaControl.insert will insert modules into module inventory if the input inventory is full. This is not how inserter behaves. We can avoid that by using the current APIs, but it is just very troublesome and not efficient (either hardcode what input inventories each entity type has, or iterate all available inventories and ignore module inventory).

Re: LuaControl.insert, but don't insert to module inventory

Posted: Sun Aug 13, 2017 11:21 am
by Klonan
Mooncat wrote:Request:
Either add an additional parameter in LuaControl.insert or make a new function to let us insert items into entity while ensuring the items won't go to the module inventory.
Also the corresponding LuaControl.can_insert parameter or function.

Currently, LuaControl.insert will insert modules into module inventory if the input inventory is full. This is not how inserter behaves. We can avoid that by using the current APIs, but it is just very troublesome and not efficient (either hardcode what input inventories each entity type has, or iterate all available inventories and ignore module inventory).
That seems awfully specific, for something which has some very easy ways to already do with the current API

Re: LuaControl.insert, but don't insert to module inventory

Posted: Mon Aug 14, 2017 2:49 am
by Mooncat
Klonan wrote:
Mooncat wrote:Request:
Either add an additional parameter in LuaControl.insert or make a new function to let us insert items into entity while ensuring the items won't go to the module inventory.
Also the corresponding LuaControl.can_insert parameter or function.

Currently, LuaControl.insert will insert modules into module inventory if the input inventory is full. This is not how inserter behaves. We can avoid that by using the current APIs, but it is just very troublesome and not efficient (either hardcode what input inventories each entity type has, or iterate all available inventories and ignore module inventory).
That seems awfully specific, for something which has some very easy ways to already do with the current API
But there are already many functions that can only perform very specific actions, which also have alternative ways to do.
Like, LuaControl.clear_items_inside, or well, all item-related functions in LuaControl, as we can get the inventories and use their functions instead. So why not add a new function that is currently NOT in LuaControl or LuaInventory?

Back to my request, as I said, the current implementation is either troublesome or inefficient. Even if we have implemented, we will need to duplicate the snippet for other mods that do the same thing. I think we all know this is bad. As this behaviour is already in vanilla game, I don't see why this shouldn't be in modding API, unless it will take you guys much time to implement. But shouldn't it be just an interface calling to your original C++ function?

If it is really difficult to implement, give it a low priority, but please don't ignore/reject it. Good modding API should give mods the ability to be as vanilla-like as possible. :mrgreen:

Re: LuaControl.insert, but don't insert to module inventory

Posted: Mon Aug 14, 2017 5:16 am
by Rseding91
In fact inserters will transfer into the module inventory of a machine should the input slots become full by the time it starts to drop the module. The exact same logic runs when you call transfer(...) that runs when an inserter transfers items into a non-belt entity.

If you don't want to transfer into what ever inventory can hold the item you need to use get_inventory(...) and transfer directly into that.

Re: LuaControl.insert, but don't insert to module inventory

Posted: Mon Aug 14, 2017 8:27 am
by Mooncat
Rseding91 wrote:In fact inserters will transfer into the module inventory of a machine should the input slots become full by the time it starts to drop the module. The exact same logic runs when you call transfer(...) that runs when an inserter transfers items into a non-belt entity.

If you don't want to transfer into what ever inventory can hold the item you need to use get_inventory(...) and transfer directly into that.
:o But...but.... but the inserter automatically stops working when the assembling machines have got enough modules in its input slot....
Oh! So the problem is not in the function for inserting items, but in the function that lets inserters detect how many ingredients are needed by its target?

How about this:
LuaEntity.get_input_items() :: dictionary string → uint [R]
Returns the fuels, ingredients, repair tools, science pack, satellites, etc. anything that can be inserted automatically by inserters, that this machine currently can take.

(Found the problem of this request. Simply don't know which fuel or repair tool is wanted.)


Edit: and could you explain, if I changed the Effective module 2 recipe to take 99x Effective module 1, why the assembling machine can take up to 242x module 1 in its input slot? :?
Why not the multiples of 50 (stack size) or 99 (ingredient count)?

Re: LuaControl.insert, but don't insert to module inventory

Posted: Mon Aug 14, 2017 2:04 pm
by Rseding91
The assembling machine allows the input slots to exceed the stack limits so you can always craft a given recipe.

You can detect what a given recipe needs by reading the recipe and looking at the ingredients.

Re: LuaControl.insert, but don't insert to module inventory

Posted: Mon Aug 14, 2017 2:52 pm
by Mooncat
Rseding91 wrote:The assembling machine allows the input slots to exceed the stack limits so you can always craft a given recipe.

You can detect what a given recipe needs by reading the recipe and looking at the ingredients.
I was thinking about a generic way that does not only work on assembling machines, but also furnaces, roboports, rocket silos...

Anyway, just found that even my second request won't work. So I guess I have no choice now but check the entity type first then get the corresponding inventory. :oops:

Thanks for your time. :mrgreen: