Page 1 of 1

BeltUpgrader not working

Posted: Wed May 24, 2017 4:45 pm
by LancerV
Have the BeltUpgrader mod installed and its always crashing at the same location:
__BeltUpgrader__/control.lua:379: attempt to get length of field 'neighbours' (a nil value)"

if #under.neighbours == 0 then --This is an orphaned underground belt
local ghost = roboport.surface.create_entity{name="entity-ghost", position=under.position, inner_name=p.name, direction = under.direction, type=under.belt_to_ground_type, force=roboport.force}
table.insert(global.ghosts, ghost)
--under.order_deconstruction(force)
count = count + 1
break
end

Re: BeltUpgrader not working

Posted: Wed May 24, 2017 4:59 pm
by daniel34
Pretty sure this is the result of viewtopic.php?f=11&t=48176

The mod author should fix this themself, or you can just replace the #under.neighbours == 0 with under.neighbours = nil (not tested).

Re: BeltUpgrader not working

Posted: Wed May 24, 2017 9:10 pm
by LancerV
Yeah that fixed it crashing but doesnt look it will upgrade them but better than nothing, thanks.

Re: BeltUpgrader not working

Posted: Wed May 24, 2017 9:37 pm
by sparr
should be "== nil"

I'm surprised "= nil" isn't throwing an error from trying to write to a read-only property.

Re: BeltUpgrader not working

Posted: Wed May 24, 2017 9:54 pm
by LancerV
I actually put ==nil without even thinking about it

Re: BeltUpgrader not working

Posted: Wed May 24, 2017 10:50 pm
by sparr
This patch will probably fix it, assuming the devs don't change it back to the more sensible "buggy" behavior before the mod authors get around to it.

Code: Select all

--- /Users/crisher/Downloads/BeltUpgrader_0.9.3/control.lua	2017-05-09 21:09:04.000000000 -0700
+++ /Users/crisher/Downloads/BeltUpgrader_0.9.3/control.lua.new	2017-05-24 15:49:04.000000000 -0700
@@ -376,7 +376,7 @@
 				--game.print("Underground belt replacement option found.  Replacing with " .. p.name)
 				if not under.to_be_deconstructed(force) then
 					-- Check neighbor to see if we can replace at the same time.
-					if #under.neighbours == 0 then --This is an orphaned underground belt
+					if under.neighbours == nil then --This is an orphaned underground belt
 						local ghost = roboport.surface.create_entity{name="entity-ghost", position=under.position, inner_name=p.name, direction = under.direction, type=under.belt_to_ground_type, force=roboport.force}
 						table.insert(global.ghosts, ghost)
 						--under.order_deconstruction(force)
@@ -386,16 +386,16 @@
 					-- We're assuming if it's in logistic range, it's in construction range.
 					-- This will cause some weird edge cases mods (super long underground belts or roboports with the same construction radius as logistic networks)
 					--if #under.neighbours == 1 and under.surface.find_logistic_network_by_position(under.position, force) then
-					if #under.neighbours == 1 then
+					if under.neighbours.valid then

 						local ghost = roboport.surface.create_entity{name="entity-ghost", position=under.position, inner_name=p.name, direction = under.direction, type=under.belt_to_ground_type, force=roboport.force}
 						table.insert(global.ghosts, ghost)
 						-- under.order_deconstruction(force)

 						--Do Neighbor
-						local ghost = roboport.surface.create_entity{name="entity-ghost", position=under.neighbours[1].position, inner_name=p.name, direction = under.neighbours[1].direction, type=under.neighbours[1].belt_to_ground_type, force=roboport.force}
+						local ghost = roboport.surface.create_entity{name="entity-ghost", position=under.neighbours.position, inner_name=p.name, direction = under.neighbours.direction, type=under.neighbours.belt_to_ground_type, force=roboport.force}
 						table.insert(global.ghosts, ghost)
-						-- under.neighbours[1].order_deconstruction(force)
+						-- under.neighbours.order_deconstruction(force)

 						count = count + 2
 						--game.print(count .. " " .. amount)