Page 1 of 1

Can not add a temp stop to a train schedule without losing the train group

Posted: Thu Feb 13, 2025 2:50 am
by hgschmie
according to FFF-389, it is possible to modify the schedule of a train within a train group by adding a temp stop without affecting the train group as a whole:

So any changes to the schedule of one member of the group will update the whole group. Importantly, this ignores the temporary stops, as they are part of the state of the individual trains (so hijacking a train to chauffeur you somewhere won't break anything).

In code, there is the TrainSchedule object which is part of the LuaTrain. It contains an array of ScheduleRecord elements (records). But this does not work:

Code: Select all

table.insert(train.schedule.records, train.schedule.current + 1, my_fancy_temp_record)
The record array is not modified. Probably because it is some fancy interface into the engine. The only thing that works is creating a copy of train.schedule, modify the schedule and re-assign it to the train.schedule attribute. But now the train group is gone (because the train has a new schedule so it is no longer part of the train group).

This seems to be a bug/limitation. I would have expected to be able to insert temporary stop records into a train schedule without losing the train group. Alternatively, assign a new schedule and as long as it contains only temp stop differences, the train would still be in the train group.

Re: Can not add a temp stop to a train schedule without losing the train group

Posted: Thu Feb 13, 2025 1:59 pm
by robot256
The FFF is referring to player-added temp stops, not API functions. The train schedule API is currently incomplete since it was not updated to handle interrupts at all.

As for why you are seeing no effect at all, that is normal and expected. The train.schedule table cannot be modified in place like that. You must store the entire table into a Lua variable, modify the table, then write the whole table back to train.schedule.

Current behavior means that any write to train.schedule will delete any train interrupts that are configured. It might also erase the train group. You can restore the train group (and any associated interrupts) by writing to train.group, but this replaces the entire schedule with the group's schedule and erases any changes you made.

Re: Can not add a temp stop to a train schedule without losing the train group

Posted: Wed Feb 26, 2025 3:38 pm
by robot256
Version 2.0.36 just dropped with a whole new class, LuaSchedule. It has accessor functions to modify schedule records AND INTERRUPTS. So now we can directly modify the schedule structure without have to write a whole new table. Enjoy!