From 7e94650b8db63d5bbb93a539657337d323c98e3c Mon Sep 17 00:00:00 2001 From: Blockhead Date: Mon, 22 Mar 2021 10:46:31 +0100 Subject: Do not crash when operating signals without interlocking The default set of signals were crashing when operated by right-clicking or mesecons when advtrains_interlocking was not enabled. --- advtrains/signals.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/advtrains/signals.lua b/advtrains/signals.lua index 59612cd..5fb1d1b 100644 --- a/advtrains/signals.lua +++ b/advtrains/signals.lua @@ -73,7 +73,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", rules=advtrains.meseconrules, ["action_"..f.as] = function (pos, node) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) - advtrains.interlocking.signal_on_aspect_changed(pos) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end }}, on_rightclick=function(pos, node, player) @@ -85,7 +87,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", advtrains.interlocking.show_ip_form(pos, pname) elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) - advtrains.interlocking.signal_on_aspect_changed(pos) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end end, -- new signal API @@ -134,7 +138,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", rules=advtrains.meseconrules, ["action_"..f.as] = function (pos, node) advtrains.setstate(pos, f.als, node) - advtrains.interlocking.signal_on_aspect_changed(pos) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end }}, on_rightclick=function(pos, node, player) @@ -146,7 +152,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", advtrains.interlocking.show_ip_form(pos, pname) elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.setstate(pos, f.als, node) - advtrains.interlocking.signal_on_aspect_changed(pos) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end end, -- new signal API @@ -206,6 +214,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", rules = mrules_wallsignal, ["action_"..f.as] = function (pos, node) advtrains.setstate(pos, f.als, node) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end }}, on_rightclick=function(pos, node, player) @@ -217,6 +228,9 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", advtrains.interlocking.show_ip_form(pos, pname) elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then advtrains.setstate(pos, f.als, node) + if advtrains.interlocking then + advtrains.interlocking.signal_on_aspect_changed(pos) + end end end, -- new signal API -- cgit v1.2.3