Hi,
I try to write a mod/object that exchanges 2 lanes of a belt. So there is an input belt, an output belt and my object between them.
I use : http://lua-api.factorio.com/0.12.27/Lua ... tLine.html
I succeed in inserting items at the entrance of the output belt-lane, checking if the belt's entrance is free (using can_insert_at_back() and insert_at_back() ),
but I wonder how you can check if the exit of the input belt-lane is containing an item. Because with get_contents() and get_item_count(), you can read all items that are in a lane, but it does not tell you where they are (at the entrance, in the middle, or ready to be extracted at the exit).
For the moment, I created an objet that extracts items from the input belt, and inserts them in the output belt. The insertion works fine, but the extraction is too quick : it extracts all items as soon as they enter the belt. So the input belt is always almost empty, letting a strange empty belt at the entrance of my object. I want to extract just those items that arrive at the end of the belt, letting the other making their full transit thru the input belt....
An idea ?
belt TransportLine functions ?
belt TransportLine functions ?
My mods on the Factorio Mod Portal
-
- Fast Inserter
- Posts: 171
- Joined: Sun Feb 17, 2013 4:31 pm
- Contact:
Re: belt TransportLine functions ?
I'm no expert modder, but you could place a hidden belt inside your lane switcher (listening to the on_built_entity, on_robot_built_entity), and take the items off of that instead?
Re: belt TransportLine functions ?
oh yes ! I don't know how to to that, but I will look further. Thanks.Rockstar04 wrote:I'm no expert modder, but you could place a hidden belt inside your lane switcher (listening to the on_built_entity, on_robot_built_entity), and take the items off of that instead?
My mods on the Factorio Mod Portal
Re: belt TransportLine functions ?
Well I tried to create this invisible transport belt, but I cannot even figure out how to describe it in data.lua.
I try to edit the original "express-transport-belt" definition, but how am I supposed to make it invisible ?... It always leads to error...
I try to edit the original "express-transport-belt" definition, but how am I supposed to make it invisible ?... It always leads to error...
My mods on the Factorio Mod Portal
Re: belt TransportLine functions ?
what you want to do is currently not possible. we discussed this topic just a few days ago.
viewtopic.php?f=25&t=21864
also bear in mind, that you are deleting the objects on the input belt and create new ones on the output belt. with the api of the transport line you have absolute no knowledge about health status of the items, or the stack size (objects on a line can also be stacks. so something that is visible to the eye as 1 ore can also be 100 ore.)
if this does not bother you, you can run your algorithm depending of the speed value of the input belt. so, not every tick, but every nth-tick. and n would be different for the 3 types of stock-belts.
(doing calculations every nth-tick is strongly recommended in any case, as it reduces workload on the game engine. imagine, there are x1000 instances of your modded entity in the game world and for each needs to be done a calculation every tick. the mod would make the game so slow, no one would install it. hereby n ticks should be the largest period possible between two calculations where what you want to do _just_ works.)
you can also probe if an item arrived at the "front" of the belt by using the can_insert_at function, with the position at the front of the line ( http://lua-api.factorio.com/0.12.27/Lua ... _insert_at ). if nothing can be inserted there, something is already there. then, and only then, you run the line switching algorithm and remove items from the line.
viewtopic.php?f=25&t=21864
also bear in mind, that you are deleting the objects on the input belt and create new ones on the output belt. with the api of the transport line you have absolute no knowledge about health status of the items, or the stack size (objects on a line can also be stacks. so something that is visible to the eye as 1 ore can also be 100 ore.)
if this does not bother you, you can run your algorithm depending of the speed value of the input belt. so, not every tick, but every nth-tick. and n would be different for the 3 types of stock-belts.
(doing calculations every nth-tick is strongly recommended in any case, as it reduces workload on the game engine. imagine, there are x1000 instances of your modded entity in the game world and for each needs to be done a calculation every tick. the mod would make the game so slow, no one would install it. hereby n ticks should be the largest period possible between two calculations where what you want to do _just_ works.)
you can also probe if an item arrived at the "front" of the belt by using the can_insert_at function, with the position at the front of the line ( http://lua-api.factorio.com/0.12.27/Lua ... _insert_at ). if nothing can be inserted there, something is already there. then, and only then, you run the line switching algorithm and remove items from the line.
Re: belt TransportLine functions ?
Hi, thanks for your help.
after what I tried, I think that get_contents() returns a list of "name" + "count", giving you vision on all items on the lane, with counts, so it should detect "stacks".
I also tried the can_insert_at function, that works to detect if the mane is full, but if I try to remove items from a full belt, the get_contents() function does not give me information on the items that are just at the exit of the lane. So when the lane is full, I just extract any item of the belt... No a good result. It's not the FIFO behaviour that I am looking for.
That's why the idea of this invisible belt seems to be a good idea. I just don't know how to describe it in data.lua...
after what I tried, I think that get_contents() returns a list of "name" + "count", giving you vision on all items on the lane, with counts, so it should detect "stacks".
Code: Select all
get_contents() → dictionary string → uint
Get counts of all items on this line.
Return value The counts, indexed by item names.
That's why the idea of this invisible belt seems to be a good idea. I just don't know how to describe it in data.lua...
My mods on the Factorio Mod Portal
Re: belt TransportLine functions ?
ok, if you want to try to go down this road, my thoughts are the following - and they are full of questionmarks:binbinhfr wrote: I also tried the can_insert_at function, that works to detect if the mane is full, but if I try to remove items from a full belt, the get_contents() function does not give me information on the items that are just at the exit of the lane. So when the lane is full, I just extract any item of the belt... No a good result. It's not the FIFO behaviour that I am looking for.
That's why the idea of this invisible belt seems to be a good idea. I just don't know how to describe it in data.lua...
lua, as javascript, is a language which can be used for object oriented programming. and for objects it uses - as javascript does - prototyping (contrary to classes used by other oo-languages). the only possible candidate for a prototype for your needs would be LuaTransportLine. in javascript, there exists the "new" operator to create new objects from a given prototype. i read the parts on oo-programming in the official lua docs ( http://www.lua.org/pil/16.html and the following pages). there seems not to be a "new" operator in lua. but there maybe a convention the defs may have followed: the "new"-method. and every LuaEntity object has a "prototype" property which reveals its prototype.
so you can try
Code: Select all
local myhiddenLineEntity = inputBelt.get_transport_line(1).prototype:new(???)
For the sake of the exploration of this topic, let us assume that
a)
Code: Select all
local myEntity = inputBelt.get_transport_line(1).prototype:new()
then you would need to
b) connect this object to one of the transport lines of the input belt
Code: Select all
inputLine.drop_target = myEntity
and again: IF drop_target even works for transport lines. if it does, the line of the input belt should put its stuff on the virtual transport line in your mods memory. and yet it is highly questionabel that an entity, which does not exist on the world map, created and connected in this way is handled correctly (or even at all) by the game engine.
tbh, it is fun to speculate, but i know nothing for real. just making assumptions. there are so many questionmarks with this approach, that i would wait for dev to walk by and shine some light on this, or - the official way - make a request for an api-enhancment in the api request forum. then we get an improved api and the devs might explain how and why it works.
greets
Re: belt TransportLine functions ?
I was more thinking about creating a new prototype in a data.lua.
Like in the VoidChest mod here :
http://www.factoriomods.com/mods/void-chest (look at the normal, non-instant version), where he creates an invisible furnace connected to his main object.
for that I think I have to do something like in this file
C:\Program Files (x86)\Steam\steamapps\common\Factorio\data\base\prototypes\entity\entities.lua
line 596.
I just have to copy and rename this express-transport-belt prototype in my own data.lua and....
to make it invisible. But that's where I don't know what to do.
If some dev is around here, I'd like a hint
Like in the VoidChest mod here :
http://www.factoriomods.com/mods/void-chest (look at the normal, non-instant version), where he creates an invisible furnace connected to his main object.
for that I think I have to do something like in this file
C:\Program Files (x86)\Steam\steamapps\common\Factorio\data\base\prototypes\entity\entities.lua
line 596.
I just have to copy and rename this express-transport-belt prototype in my own data.lua and....
to make it invisible. But that's where I don't know what to do.
If some dev is around here, I'd like a hint
My mods on the Factorio Mod Portal