TobiasM0815 Posted April 23 Share Posted April 23 Hello, I'm taking my first steps in Lua and I'm having a lot of fun. I don't really have any programming skills, but it's all logical. However, after a few hours of tinkering I've reached a problem where I'm stuck. The goal: After I arrive with my locomotive behind signal E114 in Lazy and have coupled it to the wagons, a route is to be set after ZEW1. However, the SignalTrigger does not recognize my stopping locomotive. Enclosed is the code, with a request for help. Perhaps someone can see the problem at first glance. Thank you for your help! -- SimRail - The Railway Simulator -- LUA Scripting scenario -- Version: 1.0 -- require("SimRailCore") DeveloperMode = function() return true end StartPosition = {17788.41, 338.47, 23638.06} ScenarioStep = "basic" Sounds = {} --- Function called by SimRail when the loading finishes - you should set scenario time in here, spawn trains etc. After calling this mission recorder is started and stuff gets registered function StartScenario() StartRecorder() DisplayChatText("LuaText2") SetWeather(WeatherConditionCode.ClearSky, 26, 1000, 100, 2000, 0, 10, 0, true) PlayerTrainset = SpawnTrainsetOnSignal("Player", FindSignal("LA_Tm2"), 10, true, true, false, true, { CreateNewSpawnFullVehicleDescriptor(LocomotiveNames.ET22_836, false, "", 0, BrakeRegime.P), }) PlayerTrainset.SetRadioChannel(2, true) PlayerTrainset.SetState(DynamicState.dsStop, TrainsetState.tsShunting, true) PlayerTrainset.SetAllowCouplerAttach(true) PlayerTrainset.SetAllowCouplerDetach(true) SpawnTrainsetOnSignalAsync("Cargo", FindSignal("LA_E114"), 40, false, false, true, { CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635283_3, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P), CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635283_3, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P), CreateNewSpawnFullVehicleDescriptor(FreightWagonNames._441V_31516635512_5, true, FreightLoads_412W_v4.Coal, 70, BrakeRegime.P), }, function (trainset) Trains[1] = trainset trainset.SetAllowCouplerAttach(true) trainset.SetAllowCouplerDetach(true) end) end --- Function below is called by SimRail when VD is ready to start receiving orders function OnVirtualDispatcherReady() Log("Ready!") ScenarioStep = "start" end function OnPlayerRadioCall(trainsetInfo, radio_SelectionCall) if(ScenarioStep == "neutral") then Log("No action on radio call here") end if(ScenarioStep == "start") then ScenarioStep = "neutral" CreateCoroutine(function () VDSetRoute("LA_Tm2", "LA_Tm15", VDOrderType.ManeuverRoute) VDSetRoute("LA_Tm15", "LA_Tm125", VDOrderType.ManeuverRoute) end) end if(ScenarioStep == "LAcoupled") then CreateCoroutine(function () VDSetRoute("LA_E114", "LA_Tm7", VDOrderType.ManeuverRoute) end) end end CreateSignalTrigger(FindSignal("LA_E114"), 5, { check = UnconditialCheck, result = function(e) CreateCoroutine(function() coroutine.yield(CoroutineYields.WaitForVehicleStop, RailstockGetPlayerTrainset().Vehicles[1]) ScenarioStep = "LAcoupled" Log("Now Ready for new radio call!") end) end }) Link to comment Share on other sites More sharing options...
Eridor Posted April 23 Share Posted April 23 Heya! So: signal triggers are interconnected with game refresh rate (track one are not). So giving just 5m can not catch it properly (I usually use at least 130m)) But beside of it - your code should work just fine 🙂 1 Link to comment Share on other sites More sharing options...
TobiasM0815 Posted April 23 Author Share Posted April 23 Thank you for your answer! I have increased the range to 130. Unfortunately it does not work. "ScenarioStep" seems to remain at the value "neutral" and is not changed to "LAcoupled", so that the message "No action on radio call here" continues to appear at pressing ZEW1 after coupling to the cars. I am at a bit of a loss. ^^ Link to comment Share on other sites More sharing options...
Eridor Posted April 23 Share Posted April 23 Ah.. I am not sure if you can execute trigger outside of primal functions - try to put it in StartScenario() 1 Link to comment Share on other sites More sharing options...
TobiasM0815 Posted April 24 Author Share Posted April 24 That was the problem. I put it in the primal function, then it worked! Thanks for your help! 1 Link to comment Share on other sites More sharing options...
Recommended Posts