Jump to content

Hat ein Fahrzeug einen Motor?


EricD

Empfohlene Beiträge

  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
 

Link zu diesem Kommentar
Auf anderen Seiten teilen

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

Bearbeitet von HaNNoveraNer
Link zu diesem Kommentar
Auf anderen Seiten teilen

@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

Link zu diesem Kommentar
Auf anderen Seiten teilen

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.

Bearbeitet von Goetz
Link zu diesem Kommentar
Auf anderen Seiten teilen

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto besitzen, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen.

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...