Leslie Posted May 9 Posted May 9 At program always must start iteration when you wish to access any vehicles on route (and the trigger is not the vehicle). But most cases you need only first vehicle. Please modify current routines to get first vehicle at route. Like this: getVehiclesOn("place",firstonly(boolean)) Or: getVehicleOn() In module I suggest a markbox with label: "only first vehicle". As commands and conditions. With this developing become quite easier. Thank you in advance!
Goetz Posted May 9 Posted May 9 Switch to Lua, drop the iteration (you don't need it) and pick the first item from the list: local t = layout:getVehicleGroup(vehicle) t[1].couplers[1].enabled = false disables the rear coupler of the first vehicle of a train
Phrontistes Posted May 9 Posted May 9 (edited) And t[#t].couplers[0].enabled = false disables the front coupler of the last vehicle. And this local t=layout:getVehicleGroup(vehicle) -- First Vehicle t[1].couplers[0].enabled = t[1].couplers[0].connectedCoupler ~= nil t[1].couplers[1].enabled = t[1].couplers[1].connectedCoupler ~= nil if #t > 1 then -- Last vehicle t[#t].couplers[0].enabled = t[#t].couplers[0].connectedCoupler ~= nil t[#t].couplers[1].enabled = t[#t].couplers[1].connectedCoupler ~= nil end disables the couplers at the free ends of a vehicle group. Edited May 9 by Phrontistes typo
Leslie Posted May 9 Author Posted May 9 Based on the advice of @Goetz the partial solution: Create a user-triggered event with parameter "Track": $("Events").variables["Truck"] = layout:getVehiclesOn(Track)[1] Then you find the first vehicle of given track on the module variable "Truck". Or nil if track is empty. You can use this event with any module or write it directly to LUA.
EASY Posted May 11 Posted May 11 Hi, Am 9.5.2025 um 23:03 schrieb Leslie: Based on the advice of Goetz the partial solution: Create a user-triggered event with parameter "Track": $("Events").variables["Truck"] = layout:getVehiclesOn(Track)[1] Then you find the first vehicle of given track on the module variable "Truck". Or nil if track is empty. You can use this event with any module or write it directly to LUA. Note: layout:getVehiclesOn() does not necessarily return the correct order of the vehicles within the train formation. layout:getVehicleGroup() returns the correct order... EASY
Phrontistes Posted May 11 Posted May 11 It's good that you pointed that out. I completely overlooked that @Leslie always uses getVehiclesOn instead of getVehicleGroup.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now