copying belt contents

Place to get help with not working mods / modding interface.
User avatar
hgschmie
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Tue Feb 06, 2024 5:18 am
Contact:

copying belt contents

Post by hgschmie »

So I have two belt entities, that are identical, except one has items on it and the other one has not. I want to copy the contents of one belt to the other.

I tried this:

Code: Select all

for line_index = 1, entity.get_max_transport_line_index() do
    local source = entity.get_transport_line(line_index)
    local dest = target.get_transport_line(line_index)
    for item_index = 1, #source do
        dest.insert_at_back(source[item_index])
    end
    source.clear()
end
The source belt holds a handful of entities:
Screenshot 2024-12-12 at 18.59.40.png
Screenshot 2024-12-12 at 18.59.40.png (85.08 KiB) Viewed 62 times
and the destination belt reports true for dest.can_insert_at_back() before the first entity. The first entity copies over ok but now "can_insert_at_back" is false. So it only ever copies one (the first) entity.

For both, source and destination, the line length is shown as "1" in the debugger, which is weird as the source line clearly has five entities. What am I doing wrong?
Screenshot 2024-12-12 at 19.02.46.png
Screenshot 2024-12-12 at 19.02.46.png (142.41 KiB) Viewed 62 times
Post Reply

Return to “Modding help”