From 2593b1af1625f9cc3db879541f8425217646b652 Mon Sep 17 00:00:00 2001 From: orwell96 Date: Sun, 21 Aug 2016 21:46:16 +0200 Subject: repairing the trackworker --- trainlogic.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'trainlogic.lua') diff --git a/trainlogic.lua b/trainlogic.lua index dca2863..1ec27e0 100644 --- a/trainlogic.lua +++ b/trainlogic.lua @@ -601,15 +601,15 @@ function advtrains.try_connect_trains_and_check_collision(id1, id2) end --true when trains are facing each other. needed on colliding. -- check done by iterating paths and checking their direction ---returns nil when not on the same track at all. this distinction may not always be needed. +--returns nil when not on the same track at all OR when required path items are not generated. this distinction may not always be needed. function advtrains.trains_facing(train1, train2) local sr_pos=train1.path[math.floor(train1.index)] local sr_pos_p=train1.path[math.floor(train1.index)-1] for i=advtrains.minN(train2.path), advtrains.maxN(train2.path) do if vector.equals(sr_pos, train2.path[i]) then - if vector.equals(sr_pos_p, train2.path[i+1]) then return true end - if vector.equals(sr_pos_p, train2.path[i-1]) then return false end + if train2.path[i+1] and vector.equals(sr_pos_p, train2.path[i+1]) then return true end + if train2.path[i-1] and vector.equals(sr_pos_p, train2.path[i-1]) then return false end return nil end end -- cgit v1.2.3