Long range delivery drones

by Klonan

They deliver things far far away

Content
6 months ago
1.1 - 2.0
25.7K
Logistics

b Unrecoverable error, caused by drone launching when empty

4 months ago

This error occurs if the drone launches while empty. It seems to try to read from a table of its contents but it crashes out when it doesn't get anything back.
Recommend either preventing the launch entirely (removing a timeout if present), or drone crashes shortly after launch with notification.

Error while running event Long_Range_Delivery_Drones::on_tick (ID 0)
...e_Delivery_Drones__/script/long-range-delivery-drone.lua:331: bad argument #1 of 2 to 'next' (table expected, got nil)
stack traceback:
[C]: in function 'next'
...e_Delivery_Drones__/script/long-range-delivery-drone.lua:331: in function 'deliver_to_target'
...e_Delivery_Drones__/script/long-range-delivery-drone.lua:494: in function 'update'
...e_Delivery_Drones__/script/long-range-delivery-drone.lua:1256: in function 'update_drones'
...e_Delivery_Drones__/script/long-range-delivery-drone.lua:1300: in function 'handler'
core/lualib/event_handler.lua:47: in function <core/lualib/event_handler.lua:45>

4 months ago

As an option, part of the deliver_to_target function could be wrapped in a try/catch block — in that case, empty planes will still arrive and get destroyed, but at least it won’t crash anymore.

  local success, err = pcall(function()
    local name, quality_count = next(source_scheduled)
    local quality, count = next(quality_count)
    if name and quality and count then
      count = math.min(count, get_stack_size(name))
      local target_scheduled = self.delivery_target.scheduled
      local removed = self.inventory.remove({name = name, quality = quality, count = count})
      if removed > 0 then
        self.delivery_target.inventory.insert({name = name, quality = quality, count = removed})
      end

      source_scheduled[name][quality] = source_scheduled[name][quality] - count
      if source_scheduled[name][quality] <= 0 then
        source_scheduled[name][quality] = nil
      end
      if not next(source_scheduled[name]) then
        source_scheduled[name] = nil
      end

      if target_scheduled[name] and target_scheduled[name][quality] then
        target_scheduled[name][quality] = target_scheduled[name][quality] - count
        if target_scheduled[name][quality] <= 0 then
          target_scheduled[name][quality] = nil
        end
        if not next(target_scheduled[name]) then
          target_scheduled[name] = nil
        end
      end

      delivery_time = self:make_delivery_particle(name)
    end
  end)
4 months ago

The game also crashes if you send a drone using a drone — because it tries to add a number to a table. A quick fix would be to add a type check for a number.

function safe_number(value)
  return type(value) == "number" and value or 0
end

and use it in update_logistic_filters

self.logistic_section.set_slot(slot_index, {value = DRONE_NAME, min = 1 + safe_number(self.scheduled[DRONE_NAME] or 0)})
3 months ago

I have the same error

3 months ago

我在Long Range Reusable Delivery Drones
by sanovskiy
这个模组里遇到了同样的错误,按这个方法修改后暂时没什么问题。唯一的缺点就是,请求站仍然会在错误的站点发送请求。以前游戏进行到这里就崩溃了,现在会等待半天,然后才会从正确的站点发送材料过来。

3 months ago

可能最好的方案是在没有机器人指令平台的地方使用它。如果在有机器人指令平台的地方,不要往仓库预先填充物品。

2 months ago

经过测试后,我有以下猜想:
请求站有请求时,模组会扫描哪些站点符合要求,如果没有符合要求的站点,则不建立请求,但是假如一个站点在机器人指令平台的物流系统里,而这个系统里有足够的材料,那么它就会把请求建立在这个站点,正常情况时游戏本身的物流机器人会把物资运到站点,满足数量请求后远程无人机就会运送。但是有一种情况是不正常的,就是这个站点已经充满了其他种类的物资,没有多余的格子放请求的物资,但是mod仍旧会把请求建立在这个站点,可能它认为物流机器人会把物资运过来,但事实上因为没有足够格子,物流机器人永远不可能把物资运送过来。
模组设计上应该有个最大的等待时间(或许这个时间是等待机器人把物资运过来,幸好不是等到天荒地老),时间一到,就算物资不够,也会运走(我自己测试差不多在2分钟),原来的模组里到这里飞机会运送空包出去,接着模组会崩溃,但是在以上解决办法里(感谢kolhov
),游戏不会崩溃,但是请求不能满足,它仍会在这个地方重新建立请求。如此进入循环。
改进建议:在某个仓库建立请求之前,增加一个检查,看是否有足够的格子能满足请求物资装填进来。如果能再增加一个GUI功能,查看哪些请求站的请求未能得到满足,那就更好了。

2 months ago
(updated 2 months ago)

@kolhov
大神,能否看一下另外一个模组Long Range Reusable Delivery Drones (by sanovskiy),它的无人机在返回仓库时如果恰好手动拆除了这个仓库,那么游戏必然崩溃,我不是很懂代码,尝试修改了一下,不能达到效果。如果您有时间的话,能否研究出解决方案?
作者不知道是太忙还是已经放弃该模组,我的反馈得不到回应。

2 months ago

我已经研究出来了

a month ago

@kolhov
大神,能否看一下另外一个模组Long Range Reusable Delivery Drones (by sanovskiy),它的无人机在返回仓库时如果恰好手动拆除了这个仓库,那么游戏必然崩溃,我不是很懂代码,尝试修改了一下,不能达到效果。如果您有时间的话,能否研究出解决方案?
作者不知道是太忙还是已经放弃该模组,我的反馈得不到回应。

this is a fork from this mod, so if you insert the code that is above it should work, I don't have time to do it myself right now.

New response