Page 1 of 1

on_train_created and train.id useless?

Posted: Fri May 12, 2017 9:06 am
by Optera
on_train_created and especially train.id seem less useful than I imagined they would be.
Triggering twice makes sense in all but one case

coupling two trains: fine
one trigger holding the coupled two trains as one train

decoupling trains:
fine
first trigger holding the player controlled train
second trigger holding the decoupled train

removing/destroying a carriage:
fine
one trigger for every part

placing a carriage by hand:
wtf?
first trigger seems to create a new train with the placed carriage. Why?
second trigger is the original train with the carriage attached


If you place the same entities together in the same way it has to be the same train right?
Wrong, train id constantly increases even if the train itself consists of the same entities as before adding and removing some carriages. What would have been useful is a checksum consisting of all carriages unit_number.
This makes train.id pointless for keeping track of trains, especially sice on_train_created does not always give access to the old id so you could update your references.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 10:11 am
by bobingabout
So you're saying that every time you add or remove a carriage, the train ID changes? that does sound kind of pointless and makes train IDs useless.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 10:38 am
by Optera
bobingabout wrote:So you're saying that every time you add or remove a carriage, the train ID changes? that does sound kind of pointless and makes train IDs useless.
Yes, that's exactly what happens.
Changing the id over and over would be bad in itself, but having no access to the old id through any event makes it utterly useless.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 10:41 am
by darkfrei
Can you try to move train with this mod? viewtopic.php?f=135&t=44345

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 4:22 pm
by Rseding91
The train ID changes when the LuaTrain would no longer be valid (every time a train is created).

if you're listening to the train created event then yes the ID is of no meaning to you - it's like unit number - it uniquely identifies the train.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 4:48 pm
by sparr
Rseding91 wrote:The train ID changes when the LuaTrain would no longer be valid (every time a train is created).

if you're listening to the train created event then yes the ID is of no meaning to you - it's like unit number - it uniquely identifies the train.
What field will let us keep track of the "same train", and by "same train" I mean whatever the schedule follows?

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 4:56 pm
by Rseding91
sparr wrote:
Rseding91 wrote:The train ID changes when the LuaTrain would no longer be valid (every time a train is created).

if you're listening to the train created event then yes the ID is of no meaning to you - it's like unit number - it uniquely identifies the train.
What field will let us keep track of the "same train", and by "same train" I mean whatever the schedule follows?
The schedule follows both trains. In the event that a train is split perfectly then you have 2 identical sized trains with the same schedule and same last train ID.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 5:04 pm
by sparr
Rseding91 wrote:
sparr wrote:
Rseding91 wrote:The train ID changes when the LuaTrain would no longer be valid (every time a train is created).

if you're listening to the train created event then yes the ID is of no meaning to you - it's like unit number - it uniquely identifies the train.
What field will let us keep track of the "same train", and by "same train" I mean whatever the schedule follows?
The schedule follows both trains. In the event that a train is split perfectly then you have 2 identical sized trains with the same schedule and same last train ID.
Let me rephrase my question:

What value can we follow/track in a mod that will let us identify that one previously existing train and one new train are the same train, where "same train" is defined as continuity of schedule?

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 5:21 pm
by Rseding91
I'll add "last train IDs" to the created event when it's created as a result of splitting/merging trains.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 6:15 pm
by Optera
Rseding91 wrote:I'll add "last train IDs" to the created event when it's created as a result of splitting/merging trains.
What about adding one wagon?
Will it generate a new train id or simply update the existing to include the new wagon?
In case it generates new id's for both the wagon and the train it has to fire with old_id as the trains id so we can properly update internal tracking.

What when the previously added wagon is removed again?
Basically it's now the same train we started with. It consists of the same entities with the same unit_numbers.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 6:25 pm
by sparr
Rseding91 wrote:I'll add "last train IDs" to the created event when it's created as a result of splitting/merging trains.
My interpretation:

Trains are still going to get new IDs every time you modify them. What will change is that the event will also include the previous id(s) of any train(s) that the new id(s) describe.

If you have train tracking information in your mod then you will need to update that tracking information each time the event fires.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 6:42 pm
by Rseding91
sparr wrote:
Rseding91 wrote:I'll add "last train IDs" to the created event when it's created as a result of splitting/merging trains.
My interpretation:

Trains are still going to get new IDs every time you modify them. What will change is that the event will also include the previous id(s) of any train(s) that the new id(s) describe.

If you have train tracking information in your mod then you will need to update that tracking information each time the event fires.
Correct. It already works that way for LuaTrain - the Id just makes it possible to know what some train was before it was destroyed.

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 6:46 pm
by Optera
Rseding91 wrote:
sparr wrote:
Rseding91 wrote:I'll add "last train IDs" to the created event when it's created as a result of splitting/merging trains.
My interpretation:

Trains are still going to get new IDs every time you modify them. What will change is that the event will also include the previous id(s) of any train(s) that the new id(s) describe.

If you have train tracking information in your mod then you will need to update that tracking information each time the event fires.
Correct. It already works that way for LuaTrain - the Id just makes it possible to know what some train was before it was destroyed.
Back to the add one wagon to an existing train example. Currently it fires twice and i assume that won't change.
1) on_train_created fires with the wagon
2) on_train_created fires with the train the wagon was attached to
What old_id will the 2nd time it fires hold? the wagon the train or both?

Re: on_train_created and train.id useless?

Posted: Fri May 12, 2017 8:21 pm
by Rseding91
Both.