Jump to content

Help with an event


georgeb
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

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)

1376030095_conditiontrainname.jpg.5d7a65c7d37803b5dc128d4427677395.jpg

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

Edited by Goetz
additional information
Link to comment
Share on other sites

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)

1376030095_conditiontrainname.jpg.5d7a65c7d37803b5dc128d4427677395.jpg

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Capture.JPG.6080e746a033f9cdb9956d7697549de2.JPG

Select "Keywords/Variables", and add a keyword:

Capture.thumb.JPG.09f957086ecdc3a86f7c212c86fbad82.JPG

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!)

Capture.JPG.d3e2ba9caf9083d5e1137cdd8b050495.JPG

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 

Edited by Goetz
Link to comment
Share on other sites

@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:

Capture.JPG.4106fd63ea587398b938efe091bb3a42.JPG

 

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.

Capture.JPG.61b51c11c8814c97593225124c9e59d1.JPG

 

And lastly, but MOST important, clear the name of the stored vehicle.

Capture.JPG.9bd2e674d77a222d6d85112f3a1c5b8f.JPG

 

Or, use V7. This is all handled for you, and as Goetz said, you just give the signal setting an "accelerate to" value.Capture.thumb.JPG.66ff9e417f54a51a09f568105ab97b0c.JPG

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...