Page 1 of 1
How do I insert stuff into a LogisticNetwork?
Posted: Thu Sep 13, 2018 2:07 pm
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
Re: How do I insert stuff into a LogisticNetwork?
Posted: Thu Sep 13, 2018 2:28 pm
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.
Re: How do I insert stuff into a LogisticNetwork?
Posted: Thu Sep 13, 2018 2:42 pm
by mrudat
Thanks for the help, I'll go do both. =)
Re: How do I insert stuff into a LogisticNetwork?
Posted: Thu Sep 13, 2018 5:56 pm
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).
Re: How do I insert stuff into a LogisticNetwork?
Posted: Fri Sep 14, 2018 7:57 am
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.