Jump to content

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.
  • Our servers

    • Drivers | Maszyniści Drivers | Maszyniści
      • PL2
      • pl2
      • 6 / 35
          • Percentage filling 17%
          • Most players 93
      • PL3
      • pl3
      • 3 / 78
          • Percentage filling 4%
          • Most players 76
      • PL4
      • pl4
      • 1 / 36
          • Percentage filling 3%
          • Most players 84
      • PL8
      • pl8
      • 0 / 77
          • Percentage filling 0%
          • Most players 84
      • EN1
      • en1
      • 11 / 52
          • Percentage filling 21%
          • Most players 81
      • EN2
      • en2
      • 1 / 79
          • Percentage filling 1%
          • Most players 60
      • EN3
      • en3
      • 1 / 78
          • Percentage filling 1%
          • Most players 60
      • DE1
      • de1
      • 14 / 35
          • Percentage filling 40%
          • Most players 87
      • DE3
      • de3
      • 0 / 36
          • Percentage filling 0%
          • Most players 67
      • DE4
      • de4
      • 0 / 77
          • Percentage filling 0%
          • Most players 65
      • FR1
      • fr1
      • 0 / 33
          • Percentage filling 0%
          • Most players 49
      • UA1
      • ua1
      • 0 / 34
          • Percentage filling 0%
          • Most players 27
      • CN1
      • cn1
      • 0 / 73
          • Percentage filling 0%
          • Most players 28
      • CZ1
      • cz1
      • 1 / 33
          • Percentage filling 3%
          • Most players 61
      • ES1
      • es1
      • 3 / 36
          • Percentage filling 8%
          • Most players 23
    • Dispatchers | Dyżurni ruchu Dispatchers | Dyżurni ruchu
      • PL2
      • pl2
      • 2 / 34
          • Percentage filling 6%
          • Most players 34
      • PL3
      • pl3
      • 5 / 34
          • Percentage filling 15%
          • Most players 28
      • PL4
      • pl4
      • 1 / 34
          • Percentage filling 3%
          • Most players 32
      • PL8
      • pl8
      • 0 / 34
          • Percentage filling 0%
          • Most players 27
      • EN1
      • en1
      • 9 / 34
          • Percentage filling 26%
          • Most players 34
      • EN2
      • en2
      • 2 / 34
          • Percentage filling 6%
          • Most players 21
      • EN3
      • en3
      • 0 / 34
          • Percentage filling 0%
          • Most players 13
      • DE1
      • de1
      • 7 / 34
          • Percentage filling 21%
          • Most players 34
      • DE3
      • de3
      • 0 / 34
          • Percentage filling 0%
          • Most players 29
      • DE4
      • de4
      • 4 / 34
          • Percentage filling 12%
          • Most players 29
      • UA1
      • ua1
      • 0 / 34
          • Percentage filling 0%
          • Most players 17
      • FR1
      • fr1
      • 1 / 34
          • Percentage filling 3%
          • Most players 23
      • ES1
      • es1
      • 2 / 34
          • Percentage filling 6%
          • Most players 15
      • CZ1
      • cz1
      • 0 / 34
          • Percentage filling 0%
          • Most players 28
      • CN1
      • cn1
      • 0 / 34
          • Percentage filling 0%
          • Most players 19
    • 30 Total servers
    • 74 / 1302 Total players
    • 6% Filled servers
×
×
  • Create New...

Important Information

Terms of Use Privacy Policy