February 14, 20205 yr 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
February 14, 20205 yr function GetAllLocos() local tt = {} layout:enumVehicles( function ( vehicle ) if vehicle:hasEngine() then table.insert(tt,vehicle) end end ) return tt end Edited February 14, 20205 yr by HaNNoveraNer
February 14, 20205 yr Author 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
February 14, 20205 yr @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
February 15, 20205 yr Author Hello Martin I tried .(dot) CTRL+space but not :(colon) CTRL+space. I won't make that mistake again! Best wishes Eric
February 15, 20205 yr 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, 20205 yr by Goetz
Create an account or sign in to comment