How do I insert stuff into a LogisticNetwork?

Place to get help with not working mods / modding interface.
Post Reply
User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 229
Joined: Fri Feb 16, 2018 5:21 am
Contact:

How do I insert stuff into a LogisticNetwork?

Post by mrudat »

Answer
It looks like the API docs are incorrect, it does indeed accept a SimpleItemStack, so the below code should work as I had expected.
Rseding91 wrote:
Fri Sep 14, 2018 7:41 am
The docs are outdated. It's already fixed in 0.17.
Original Question
As far as I can tell, LuaLogisticNetwork.insert(item,members) requires as its first parameter a LuaItemStack.

Also a LuaItemStack can't be instantiated as a new object via Lua, it can only be retrieved by acquiring one from some other object, usually representing a portion of an inventory somewhere, so manipulating the LuaItemStack will also manipulate the inventory that you acquired the object from.

This suggests that it isn't possible to, for example:

Code: Select all

local function add_10_iron-plate_to_logistic_network(logistic_network)
    logistic_network.insert({ name="iron-plate", count=10 })
end
...am I correct in the assumption that if I want to create some items from nothing and inject them into a logistic network that I would need to do something along the lines of:
  • iterate over all of the storage chests in the network
  • find one with free space
  • stick the items I want to add into that storage chest

Edit: indent code sample
Edit: add answer
Last edited by mrudat on Fri Sep 14, 2018 8:36 am, edited 2 times in total.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: How do I insert stuff into a LogisticNetwork?

Post by DaveMcW »

An easier way is:

1. chest = surface.create_entity{name = "steel-chest"}
2. chest.insert{SimpleItemStack}
3. logistic_network.insert(chest.get_inventory(1)[1])
4. chest.destroy()

Allowing SimpleItemStack in LuaLogisticNetwork.insert() sounds like a good idea for Modding interface requests.

User avatar
mrudat
Fast Inserter
Fast Inserter
Posts: 229
Joined: Fri Feb 16, 2018 5:21 am
Contact:

Re: How do I insert stuff into a LogisticNetwork?

Post by mrudat »

Thanks for the help, I'll go do both. =)

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How do I insert stuff into a LogisticNetwork?

Post by eradicator »

Uhm? The API page you quoted explains how the second parameter works, and that it is a simple string, in your case you'd probably want to use "storage" as you're not inserting a whole stack.
Bleh, it says ItemStack and not SimpleItemStack... that might be worth a request.
Depending on what / when you need to insert the thing you want to you can also use an item-on-ground or the players cursor or something :D.
If you need to do it often you should consider not recreating/destroying the chest every time and instead create a permanent invisible chest somewhere (=somewhere you know exists, some mods delete chunks to free disk space).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: How do I insert stuff into a LogisticNetwork?

Post by bobingabout »

one of the most anoying things I found is that in the data phase, recipes are referenced as {item, amount} EG {"wood", 2} as their simple form, or {type = type, name = name, amount = amount} eg {type = "fluid", name = "water", amount = 12.5} in their long form.

simple item stack in the run-time phase is in the format {name = name, count = amount} eg {name = "wood", count = 50}.

Why is it amount in data and count in run-time?

The first time I tried to use the run-time commands, I used data phases simple form, .insert({"wood", 5}), and when that didn't work, I tried .insert({name = "wood", amount = 5}) and that didn't work either, at which point I had to look up to see what it wanted, and had that WTF moment when I saw it used count instead of amount.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Post Reply

Return to “Modding help”