Jump to content

Recommended Posts

Posted

  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
 

Posted (edited)

function GetAllLocos()
      local tt = {}
      layout:enumVehicles(
      function ( vehicle )
         if vehicle:hasEngine()  then
           table.insert(tt,vehicle)
         end
      end
      )
      return tt
  end

Edited by HaNNoveraNer
Posted

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

 

Posted

@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

Posted (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 by Goetz

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...