Jump to content
Następne podsumowanie tygodnia pojawi się 21.09 | The next summary of the week will be published on 21.09

My first steps..


Recommended Posts

 

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

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 🙂

  • Thanks 1
Link to comment
Share on other sites

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Terms of Use Privacy Policy