Jump to content

I would use a script, if I knew how...


Empfohlene Beiträge

Good evening...

I have a one-time repetitive task to execute, to change a few properties on every vehicle in a layout. I have the Lua Tutorial (in German; I've translated it into English...) and have just received, this morning, my copy of Programming In Lua, 4th Edition. My request is this: I believe that it's possible, and relatively simple, to create a script which would sweep through all the vehicles, and give them all, without exception, these properties: Auto braking, Auto acceleration, No front coupling, No rear coupling. Would anyone care to write such a script, which I would then use as a stepping-off point for diving further into creating scripts in general..? Is this as simple as I think..? Any help would be appreciated; thanks in advance. rWNVV2D.gif

Guten Abend...

Ich muss eine einmalige sich wiederholende Aufgabe ausführen, um einige Eigenschaften für jedes Fahrzeug in einem Layout zu ändern. Ich habe das Lua-Tutorial (auf Deutsch; ich habe es ins Englische übersetzt ...) und habe heute Morgen meine Kopie von Programming In Lua, 4. Auflage, erhalten. Meine Bitte lautet: Ich glaube, dass es möglich und relativ einfach ist, ein Skript zu erstellen, das alle Fahrzeuge durchläuft und allen ausnahmslos die folgenden Eigenschaften verleiht: Automatisches Bremsen, Automatische Beschleunigung, Keine vordere Kupplung, Kein Heck Kupplung. Würde es jemandem etwas ausmachen, ein solches Skript zu schreiben, das ich dann als Ausgangspunkt verwenden würde, um weiter in das Erstellen von Skripten im Allgemeinen einzutauchen? Ist das so einfach wie ich denke ..? Jede Hilfe wäre dankbar; Danke im Voraus. rWNVV2D.gif

Douglas

Link zu diesem Kommentar
Auf anderen Seiten teilen

vor 6 Stunden schrieb Dad3353:

Auto braking, Auto acceleration, No front coupling, No rear coupling.

coming up:

layout:enumVehicles(
  function (vehicle)
    vehicle.autoAcceleration = true
    vehicle.autoDeceleration = true
    vehicle.couplers[0].enabled = false
    vehicle.couplers[1].enabled = false
  end
)

 

If you enter this code into the main script, it will be executed once when you load your layout.

995920347_mainscript.jpg.15d6dbaa61fc85320c226b593c417e7d.jpg

 

Alternatively, you may enter it into an event which is triggered by flipping a switch, setting a signal, entering a specific track etc., if you have the need to call it again during the use of your layout ...

greets
Goetz

Bearbeitet von Goetz
added remarks
Link zu diesem Kommentar
Auf anderen Seiten teilen

Perfect, Goetz, it's exactly what I was hoping for. I typed it in, and didn't realise that it has immediate effect; all the vehicles suddenly had these properties set. I've learned, then, to put these scripts into a User Event, to be triggered when required. No problem for this example, as I only wanted it to correct the whole layout one time, and it did that.
Using this same principle, I made a script to allocate a Keyword to all vehicles, and that seems to have worked. The vehicles have them, but I can't see the Keywords when I want to use them as a condition for an Event. All road vehicles have the Keyword 'Road', for instance (with a value of 0...); I wish to have a 'Start' switch which will set all vehicles with the Keyword 'Road' to 30 km/h, but not start the trains. These will have a different Keyword associated with them. I've looked at the examples and videos that we did together, and others, but have not yet found the Key to Keywords..! Progress, though; thanks again for the script. rWNVV2D.gif

Perfekt, Goetz, genau das habe ich mir erhofft. Ich tippte es ein und merkte nicht, dass es unmittelbare Wirkung hat. Alle Fahrzeuge hatten plötzlich diese Eigenschaften eingestellt. Ich habe also gelernt, diese Skripte in ein Benutzerereignis einzufügen, um sie bei Bedarf auszulösen. Kein Problem für dieses Beispiel, da ich wollte, dass das gesamte Layout nur einmal korrigiert wird, und das tat es auch.
Nach dem gleichen Prinzip habe ich ein Skript erstellt, um allen Fahrzeugen ein Schlüsselwort zuzuweisen, und das scheint funktioniert zu haben. Die Fahrzeuge haben sie, aber ich kann die Schlüsselwörter nicht sehen, wenn ich sie als Bedingung für ein Ereignis verwenden möchte. Alle Straßenfahrzeuge haben beispielsweise das Schlüsselwort 'Straße' (mit einem Wert von 0 ...); Ich möchte einen Startschalter, der alle Fahrzeuge mit dem Schlüsselwort "Straße" auf 30 km / h einstellt, aber die Züge nicht startet. Diesen ist ein anderes Schlüsselwort zugeordnet. Ich habe mir die Beispiele und Videos angesehen, die wir zusammen und andere gemacht haben, aber den Schlüssel zu den Schlüsselwörtern noch nicht gefunden. Fortschritt jedoch; Nochmals vielen Dank für das Skript. 
rWNVV2D.gif

Douglas

Link zu diesem Kommentar
Auf anderen Seiten teilen

vor 1 Stunde schrieb Dad3353:

to put these scripts into a User Event

is smart thinking. Well done, Douglas  (y)

 

vor 1 Stunde schrieb Dad3353:

All road vehicles have the Keyword 'Road', for instance (with a value of 0...);

 

The value of 0 indicates, that they are variables for numbers, not keywords.
The command to set a keyword is:

 

contact.variables["road"] = keyword

 

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...