AndiS wrote:And signalling items cannot be scenario-specific.
Yes they can
--------------------------------------------------------------------------------------
-- Detonator Signal
-- AndiS for Pete who told him about scenario-specific signals
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
-- INITIALISE
--
function Initialise ()
end
--------------------------------------------------------------------------------------
-- ON CONSIST PASS
--
function OnConsistPass ( prevFrontDist, prevBackDist, frontDist, backDist, linkIndex )
-- if the consist is crossing the signal now
if ( frontDist > 0 and backDist < 0 ) or ( frontDist < 0 and backDist > 0 ) then
-- if the consist was previously before/after siganl then the crossing has just started
if ( prevFrontDist < 0 and prevBackDist < 0 ) or ( prevFrontDist > 0 and prevBackDist > 0 ) then
-- Request state of next signal
local nextSignalState = Call( "GetNextSignalState", "", 1, 1, 0 )
Print("Next state is " .. nextSignalState)
if (nextSignalState == BLOCKED) then -- choose one, i.e., either bang on stop aspect only
-- if (nextSignalState ~= CLEAR) then -- or on anything but clear
-- Set sound controlling parameter, triggering the sound
Call ("Sound:SetParameter", "SignalProgress", 1)
Print("Detonator sound started")
end
end
-- otherwise the consist is not crossing the signal now
else
-- the the consist was previously crossing the signal, then it has just finished crossing
if ( prevFrontDist < 0 and prevBackDist > 0 ) or ( prevFrontDist > 0 and prevBackDist < 0 ) then
-- Reset sound controlling parameter - does not hurt to do it too often
Call ("Sound:SetParameter", "SignalProgress", 0)
end
end
end
--------------------------------------------------------------------------------------
-- ON SIGNAL MESSAGE
--
function OnSignalMessage( message, parameter, direction, linkIndex )
-- We could monitor SIGNAL_BLOCKED, SIGNAL_CLEARED etc. here to decide when to sound the bang,
-- but GetNextSignalState works just fine and is simpler
-- Forward each message
if ( parameter ~= "DoNotForward" ) then
Call( "SendSignalMessage", message, parameter, -direction, 1, linkIndex )
end
end
-- States
CLEAR = 0
WARNING = 1
BLOCKED = 2
Users browsing this forum: No registered users and 1 guest