georgeb Geschrieben 7. November 2021 Geschrieben 7. November 2021 I need to identify the Train Name when is enters a section. I would like to place conditions on the train behaviour (speed, route etc..) based on that train name containing a supplied word. If train name contains "London" then set train speed to 80 Any help appreciated.
Goetz Geschrieben 7. November 2021 Geschrieben 7. November 2021 (bearbeitet) Hello Jud91, the name of the train is one of its properties. And the train, which initiated the event, is one of two triggers (the other being the contact) Please click on a small cog wheel icon to change from variable to property, to select a trigger or to change the type to text field Kind regards Goetz Bearbeitet 7. November 2021 von Goetz additional information
georgeb Geschrieben 7. November 2021 Autor Geschrieben 7. November 2021 The Name is not London - it may be London Up Fast and I only need to know if the word London is in the name (not the whole name). OK/ Thanks for the tip on change to property. Great Help - Thanks George
georgeb Geschrieben 7. November 2021 Autor Geschrieben 7. November 2021 8 hours ago, Goetz said: Hello Jud91, the name of the train is one of its properties. And the train, which initiated the event, is one of two triggers (the other being the contact) Please click on a small cog wheel icon to change from variable to property, to select a trigger or to change the type to text field Kind regards Goetz I have managed to find the code on the internet:- Train Name = "Down Fast London for P2". It set the absolute speed to 20 for this train and to 10 for all others if string.find(vehicle.name,"London") then layout:enumVehicles( function (vehicle) if vehicle:hasEngine() then vehicle.engine.active = true vehicle.targetSpeedAbs = 20 end end ) else layout:enumVehicles( function (vehicle) if vehicle:hasEngine() then vehicle.engine.active = true vehicle.targetSpeedAbs = 10 end end ) end Thank you Goetz for your help in getting me there. George
Neo Geschrieben 7. November 2021 Geschrieben 7. November 2021 Hi George, vor 47 Minuten schrieb Jud91: It set the absolute speed to 20 for this train and to 10 for all others your code sets the speed for all vehicles in your layout, is this really wanted? A better approach for defining different behaviors of different trains is by using keywords. Add the same keyword to all trains which should react in the same way and create your event only for this keyword. This is way faster than searching for substrings. Kind regards, Neo
simonjackson1964 Geschrieben 7. November 2021 Geschrieben 7. November 2021 5 hours ago, Jud91 said: The Name is not London - it may be London Up Fast and I only need to know if the word London is in the name (not the whole name). OK/ Thanks for the tip on change to property. Great Help - Thanks George 3 hours ago, Neo said: Hi George, your code sets the speed for all vehicles in your layout, is this really wanted? A better approach for defining different behaviors of different trains is by using keywords. Add the same keyword to all trains which should react in the same way and create your event only for this keyword. This is way faster than searching for substrings. Kind regards, Neo If you select the locomotive, then click on the three-bar menu icon at the top-right of the tool ribbon (see below) this opens events & Keywords/variables menu Select "Keywords/Variables", and add a keyword: Give the keyword a meaningful name, such as "London in name". You can then add the same keyword to all locomotives with "London"in the name. Then you select the contact that you want to use to affect the speed. Again, if you want it to happen on more than one contact, create a keyword on that contact, that means something to you. Say "London Train Triggered" Then create an event, for when the track contact is triggered. Change the name to something meaningful Then select the name of the track contact at the top, and replace it with "Select (Keyword)". From the drop-down in the pop-up menu, select the keyword you put on the contact. This will activate this event for all contacts with that keyword, and no others. Now create a condition on the event, as below, being careful to change the value of "Trigger" from "Contact" to "Vehicle", otherwise none of it works! (Learned this the hard way!) Finally, put the actions you wish to take - setting the vehicle speed, activating routes (V7) or setting points and signals (V4-6). They will only happen if the keyword "London In Name" is present on the triggering vehicle. And of course you can specify actions to take if it is not. That's the "Janet And John" version. I think when we're so familiar with how things work, we often forget that someone knew to the software might not know something the rest of us take for granted. If you already know most or all of this, please ignore, but Neo's post takes for granted that you know what a keyword is and how to create one. No reflection on Neo, of course, as it's a fairly common assumption, I've noticed! Cheers Simon
georgeb Geschrieben 8. November 2021 Autor Geschrieben 8. November 2021 Just for the record: I did not know about keywords. Thanks. George
simonjackson1964 Geschrieben 8. November 2021 Geschrieben 8. November 2021 You are welcome. When @Goetz first told me what they are and how to use them, I thought, "Meh, can't see them being much use", but now I use them all over the place, to dictate which events run in which circumstances. You can use a single track contact and have a whole raft of keywords on it, that all trigger different events. The important thing is to make sure the events don't conflict with each other! I also use lists and iterations. A track contact at the start of two or more different routes will have a keyword something like "Junction" or "Choose Route", and a list of all the available routes. A locomotive will also have a list of the routes it needs to choose. The event activated by the loco triggering the track contact with that keyword will iterate the available routes and within that iterate the loco's choices, and set the route when it finds a match. If it doesn't find a match it doesn't set a route and the train is stopped at the next signal! (It's possible to reverse the nesting of the iterations, but it really makes little difference). Anyway, have fun! Simon
georgeb Geschrieben 9. November 2021 Autor Geschrieben 9. November 2021 22 hours ago, simonjackson1964 said: You are welcome. When Goetz first told me what they are and how to use them, I thought, "Meh, can't see them being much use", but now I use them all over the place, to dictate which events run in which circumstances. You can use a single track contact and have a whole raft of keywords on it, that all trigger different events. The important thing is to make sure the events don't conflict with each other! I also use lists and iterations. A track contact at the start of two or more different routes will have a keyword something like "Junction" or "Choose Route", and a list of all the available routes. A locomotive will also have a list of the routes it needs to choose. The event activated by the loco triggering the track contact with that keyword will iterate the available routes and within that iterate the loco's choices, and set the route when it finds a match. If it doesn't find a match it doesn't set a route and the train is stopped at the next signal! (It's possible to reverse the nesting of the iterations, but it really makes little difference). Anyway, have fun! Simon Is there anywhere (in English) with examples that I can understand lists and choice from a list?
Goetz Geschrieben 9. November 2021 Geschrieben 9. November 2021 Hello @Jud91 I made a video not long ago which may help? Kind regards Goetz
simonjackson1964 Geschrieben 9. November 2021 Geschrieben 9. November 2021 Yes! That one! In fact, at V7 it's even easier, you just select the correct route.
georgeb Geschrieben 9. November 2021 Autor Geschrieben 9. November 2021 8 hours ago, Goetz said: Hello Jud91 I made a video not long ago which may help? Kind regards Goetz Brilliant. Thank you. two methods in one video.
georgeb Geschrieben 10. November 2021 Autor Geschrieben 10. November 2021 Is it possible to remove a keyword from a locomotive via a track contack?
Goetz Geschrieben 10. November 2021 Geschrieben 10. November 2021 vor einer Stunde schrieb Jud91: Is it possible to remove a keyword from a locomotive via a track contack? Yes, that's possible, Jud You can use the delete variable command. Use extended variable, to chose the triggering vehicle as the object from which the variable is to be deleted. Greets Goetz
HaNNoveraNer Geschrieben 10. November 2021 Geschrieben 10. November 2021 Götz is ever faster... Demo.mbp
georgeb Geschrieben 13. November 2021 Autor Geschrieben 13. November 2021 I have a train at a red signal, brought to a halt by a deceleration contact. When the signal goes to clear I want the train to move off to, say, 25 km/hr. Is there a global event which can check or do I need to do it by a variable change when the signals clear?
Goetz Geschrieben 13. November 2021 Geschrieben 13. November 2021 (bearbeitet) Hello Jud, you may configure the signal‘s contact differently for each signal aspect. Set the acceleration value to 25 for the „clear“ aspect and the train will be set in motion automatically when the signal changes. greets Goetz Bearbeitet 13. November 2021 von Goetz
simonjackson1964 Geschrieben 14. November 2021 Geschrieben 14. November 2021 @Jud91 Which version are you using? This would be handled differently at V5, V6 and V7. (I don't remember enough about V4 to say). At V5, it's a bit more complex, but you mentioned a deceleration contact - those didn't exist at V5. V6: First store the Object ID of the vehicle, when it arrives at the deceleration contact, in a variable on the associated signal. NB: You will need a variable on the contact with the object ID of the signal: When the signal changes, check to see if there is a stored vehicle. If there is, set its speed according to your track and the signal aspect. And lastly, but MOST important, clear the name of the stored vehicle. Or, use V7. This is all handled for you, and as Goetz said, you just give the signal setting an "accelerate to" value.
georgeb Geschrieben 14. November 2021 Autor Geschrieben 14. November 2021 21 hours ago, Goetz said: Hello Jud, you may configure the signal‘s contact differently for each signal aspect. Set the acceleration value to 25 for the „clear“ aspect and the train will be set in motion automatically when the signal changes. greets Goetz Thanks again. So obvious when you see it.
georgeb Geschrieben 14. November 2021 Autor Geschrieben 14. November 2021 I do have V7 BUT I like to see it in V6 as well. A very good (and well presented) solution to the problem. I can use this "Train AT" method in other areas. Many, many thanks. George
Empfohlene Beiträge
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 erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden