Liebe Community!
Ich versuche gerade eine Skript Update für den RSSLO 4010 zu machen. Dafür habe ich erstmal die wichtigsten Funktionen definiert, Die Initialise(), Setup(), Update(interval) und OnControlValueChange(name, index value). Alle sind in der Script_OBB4010.lua. Für alle habe ich Print Statements eingefügt, um in LogMate zu sehen, ob alles funktioniert, wie erwartet. Die Setup Methode wird jedoch nur in der SimpleEngineSimulation aufgerufen, die Setup Methode allgemein nie, egal ob von der Script_OBB4010.lua oder von der SimpleEngineSimulation.lua. Das macht für mich aber absolut keinen Sinn, muss davor irgendwas passieren, damit die Methoden aufgerufen werden? Habe ich etwas falsch definiert?
Script_OBB4010:
Code
isInitialized = false
lastPantoFrontValue = 0
lastPantoBackValue = 0
function Initialise()
Print("[Init] Locomotive script loaded. From OBB4010.lua")
end
function Setup ()
Print("[DEBUG] Setup method called in script.")
end
function Update (interval)
Print("[UPDATEMETHOD] called update from SCRIPT!")
end
function OnControlValueChange(name, index, value)
Print("[ControlValueChanged] Control changed with name " .. name .. " and index " .. index .. " and value " .. value)
if not isInitialized then
Call("*:SetControlValue", "VirtualThrottle", 0, 0.5)
Call("*:SetControlValue", "Pantograph_Kontrol", 0, 2)
Print("Throttle set to initial position")
isInitialized = true
end
if name == "Reverser" then
local reverserValue = Call("*:GetControlValue", "Reverser", 0)
Print("[ControlValueChanged] Reverser value is " .. reverserValue)
elseif name == "Pantograph_Kontrol" then
local pantoValue = Call("*:GetControlValue", "Pantograph_Kontrol", 0)
local correctedPantoValue = CorrectPantoPosition(pantoValue)
if correctedPantoValue == 0 then
Call("*:SetControlValue", "Pantograph_Control_Front", 0, 0)
Call("*:SetControlValue", "Pantograph_Control_Back", 0, 1)
Call("SendConsistMessage", PANTOGRAPH, "Pantograph_Control_Back = 1", 1)
Print("[Panto Control] Front pantograph active")
elseif correctedPantoValue == 4 then
Call("*:SetControlValue", "Pantograph_Control_Front", 0, 1)
Call("*:SetControlValue", "Pantograph_Control_Back", 0, 0)
Call("SendConsistMessage", PANTOGRAPH, "Pantograph_Control_Front = 1", 1)
Print("[Panto Control] Rear pantograph active")
else
Call("*:SetControlValue", "Pantograph_Control_Front", 0, 0)
Call("*:SetControlValue", "Pantograph_Control_Back", 0, 0)
Call("SendConsistMessage", PANTOGRAPH, "0", 1)
Print("[Panto Control] No pantograph active")
end
local frontPantographAnimation = Call("*:GetControlValue", "Pantograph_Front_Animation", 0)
local backPantographAnimation = Call("*:GetControlValue", "Pantograph_Back_Animation", 0)
if frontPantographAnimation > 0.99 or backPantographAnimation > 0.99 then
Print("[ControlValueChanged] At least one panto fully deployed")
Call("*:SetControlValue", "PantographControl", 0, 1)
Call("*:SetControlValue", "MainLine", 0, 15)
elseif frontPantographAnimation <= 0.99 and backPantographAnimation <= 0.99 then
Print("[ControlValueChanged] No pantos fully deployed - cutting power")
Call("*:SetControlValue", "PantographControl", 0, 0)
Call("*:SetControlValue", "MainLine", 0, 0)
-- Optionally reset MainLine to 0 if needed
end
end
Print("[ControlMethod] name is: " .. name)
end
function CorrectPantoPosition(pantoValue)
local correctedPantoValue = 0
if pantoValue >= 0 and pantoValue < 0.5 then
correctedPantoValue = 0
elseif pantoValue >= 0.5 and pantoValue < 1.5 then
correctedPantoValue = 1
elseif pantoValue >= 1.5 and pantoValue < 2.5 then
correctedPantoValue = 2
elseif pantoValue >= 2.5 and pantoValue < 3.5 then
correctedPantoValue = 3
elseif pantoValue >= 3.5 then
correctedPantoValue = 4
end
Call("*:SetControlValue", "Pantograph_Kontrol", 0, correctedPantoValue)
return correctedPantoValue
end
Alles anzeigen
SimpleEngineSimulation: