Most of these luggage vans were fitted with removable / mobile tail lamps. They had a day and a night position - train stuff had to turn them 90° and light up the paraffin oil lamp at night.
day position
night position
I am trying to implement this function in my models via lua. The lamp has to be "turned around" by the script when the light is getting turned on or off. Until now, this doesn't work, no matter what I try. The rest of the script controls the visibility of the brake hoses an steam couplings between wagons of the same type in a consist - and this part of the script is working as it should (to be honest, it was developed for my "Umbauwagen" models with much more than a little help by some of you).
My tail lamp is a child object called "Zugschlusslaterne", and it consists of four nodes: "Lampe_V-T" (lamp front day position), "Lampe_V-N" (lamp front night position), "Lampe_H-T" (lamp rear day position), "Lampe_H-N" (lamp rear night position).
There are two variables for them (gtaillamp_front and gtaillamp_rear) whose value changes from "0" to "1" if the van is the last or first one in a consist. When the control value "Headlights" change the nodes should turn on or off. This part doesn't work and I con't find my probably very simple error Im am pretty sure that this is a case for the thread "developer fails of the day".
Thank you for some help!
- Code: Select all
-- File: MDie_WagonScript.lua
-- Version: 1.00
-- Beschreibung: steuert Sichtbarkeit Wagenuebergaenge und Schlusslaternen
-- Entwickler
-- Sprache Heiko Mueller
-- erstellt: 01.05.1016
-- Letzte Aenderung: 10.06.2016
--------------------------------------------------------------------------------------------------------
-- Variablen
---------------------------------------------------------------------------------------------------------
WAGENTYP_ID = 500;
DHZ_ID = 2000;
gZuglaenge = 0;
gfront_probe = 0;
grear_probe = 0;
gtaillamp_front = 0;
gtaillamp_rear = 0;
function Initialise()
Call( "Dampfheizung_1:SetEmitterActive", 0 );
Call( "Dampfheizung_2:SetEmitterActive", 0 );
Call( "Dampfheizung_3:SetEmitterActive", 0 );
Call( "Dampfheizung_4:SetEmitterActive", 0 );
Call( "Fwd_Taillight_01:Activate", 0);
Call( "Bwd_Taillight_01:Activate", 0);
Call( "BeginUpdate" );
firstUpdate = true
end
function Update ( time )
if firstUpdate then
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-T", 0 ); -- all tail lamps off
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-T", 0 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-N", 0 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-N", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vzu", 1 );
Call( "Uebergang_MDie:ActivateNode", "Hauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hzu", 1 );
firstUpdate = false
end
-- consist lenght check
local Tempo = Call("GetSpeed");
if Tempo < 2.0 then
local Laengenpruefung = Call( "GetConsistLength" );
if gZuglaenge ~= Laengenpruefung then
gZuglaenge = Laengenpruefung;
gfront_probe = Call( "SendConsistMessage", WAGENTYP_ID, 4, 0 );
grear_probe = Call( "SendConsistMessage", WAGENTYP_ID, 4, 1 );
end
end
if gfront_probe == 0 then
Call( "Uebergang_MDie:ActivateNode", "Vauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vzu", 1 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-T", 1 );
gtaillamp_front = 1
else Call( "SendConsistMessage", WAGENTYP_ID, 4, 0);
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-T", 0 );
end
if grear_probe == 0 then
Call( "Uebergang_MDie:ActivateNode", "Hauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hzu", 1 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-T", 1 );
gtaillamp_rear = 1
else Call( "SendConsistMessage", WAGENTYP_ID, 4, 1)
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-T", 0 );
end
end
function OnControlValueChange ( name, index, value )
if ( Call("*:GetControlValue", "Headlights", 0) >= 0.5 ) and ( gtaillamp_front == 1 ) then
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-T", 0 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_V-N", 1 );
end
if ( Call("*:GetControlValue", "Headlights", 0) >= 0.5 ) and ( gtaillamp_rear == 1 ) then
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-T", 0 );
Call( "Zugschlusslaterne:ActivateNode", "Lampe_H-N", 1 );
end
end
function OnConsistMessage ( msg, argument, direction )
if ( msg == WAGENTYP_ID ) and ( argument == "4" ) and ( direction == 0 ) then
Call( "Uebergang_MDie:ActivateNode", "Hauf", 1 );
Call( "Uebergang_MDie:ActivateNode", "Hauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hzu", 0 );
Call( "SendConsistMessage", WAGENTYP_ID, 4, 0);
elseif ( msg == WAGENTYP_ID ) and ( argument == "4" )and ( direction == 1 ) then
Call( "Uebergang_MDie:ActivateNode", "Vauf", 1 );
Call( "Uebergang_MDie:ActivateNode", "Vauf_2", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vzu", 0 );
Call( "SendConsistMessage", WAGENTYP_ID, 4, 1);
elseif ( msg == WAGENTYP_ID ) and ( argument == "2" ) and ( direction == 0 ) then
Call( "Uebergang_MDie:ActivateNode", "Hauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Hauf_2", 1 );
Call( "Uebergang_MDie:ActivateNode", "Hzu", 0 );
Call( "SendConsistMessage", WAGENTYP_ID, 4, 0);
elseif ( msg == WAGENTYP_ID ) and ( argument == "2" ) and ( direction == 1 ) then
Call( "Uebergang_MDie:ActivateNode", "Vauf", 0 );
Call( "Uebergang_MDie:ActivateNode", "Vauf_2", 1 );
Call( "Uebergang_MDie:ActivateNode", "Vzu", 0 );
Call( "SendConsistMessage", WAGENTYP_ID, 4, 1);
else Call( "SendConsistMessage", msg, argument, direction );
end
end