EricD Posted February 14, 2020 Posted February 14, 2020 Hello Members Please can someone help me with the following. I am trying to build a table containing all the Locomotives in the layout. I cannot find the Lua code corresponding to "the vehicle has an engine" in the following: function GetAllLocos() local tt = {} g = layout:enumVehicles( function ( vehicle ) if "the vehicle has an engine" then table.insert(tt,vehicle) end end ) return tt end I have searched the forum for quite a long time before making this request. I hope some kind person will tell me the solution. Thank you Eric ---------------------------------------- Google translation: Bitte kann mir jemand bei folgendem helfen. Ich versuche eine Tabelle mit allen Lokomotiven zu erstellen im Layout. Ich kann den entsprechenden Lua-Code nicht finden "Das Fahrzeug hat einen Motor" im Folgenden: <Lua function> Ich habe das Forum ziemlich lange durchsucht, bevor ich es gemacht habe diese Anfrage. Ich hoffe, eine freundliche Person wird mir die Lösung sagen. Vielen Dank Eric
HaNNoveraNer Posted February 14, 2020 Posted February 14, 2020 layout:enumVehicles( function(vehicle) print(vehicle:hasEngine()) end )
HaNNoveraNer Posted February 14, 2020 Posted February 14, 2020 (edited) function GetAllLocos() local tt = {} layout:enumVehicles( function ( vehicle ) if vehicle:hasEngine() then table.insert(tt,vehicle) end end ) return tt end Edited February 14, 2020 by HaNNoveraNer
EricD Posted February 14, 2020 Author Posted February 14, 2020 Thank you HaNNoveraNer I had a memory of "hasEngine" but I was trying vehicle.hasEngine. Once again: thanks for your quick reply. Best wishes Eric
martin51 Posted February 14, 2020 Posted February 14, 2020 @Eric Danvers Hello Eric, I don't know if you know this for information all Lua functions and properties are documented directly in the script editor by auto-completion Press colon (:) for a list of all functions, dot (.) for a list of all properties and CTRL+space for an overview of all global variables and parameters. NEO has answered a question from TIMBA every vehicle has the function "hasEngine", with which you can check if it is a powered vehicle local vehicles = layout:getVehiclesOnTrack(...) for k, v in pairs(vehicles) do if v:hasEngine() then -- Vehicle ist eine Lok end end Best wishes Martin
EricD Posted February 15, 2020 Author Posted February 15, 2020 Hello Martin I tried .(dot) CTRL+space but not :(colon) CTRL+space. I won't make that mistake again! Best wishes Eric
Goetz Posted February 15, 2020 Posted February 15, 2020 (edited) vor 20 Stunden schrieb Eric Danvers: I was trying vehicle.hasEngine. That would be a variable or property. Separated by a single colon. The double colon is needed for a function or method. It includes the object (= what's in front of the colon) as the first argument. Edited February 15, 2020 by Goetz
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