Page 1 of 1

[2.0.37] LuaSchedule::add_record adds temporary stops at the beginning of the schedule

Posted: Fri Feb 28, 2025 3:20 am
by hgschmie
( this is a debugging session with an actual train and schedule )

Code: Select all

> for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
(nil)
> train_schedule.add_record { station = 'zzz_first' }
> train_schedule.add_record { station = 'aaa_second' }
> for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
{allows_unloading = true, created_by_interrupt = false, station = "zzz_first", temporary = false, wait_conditions = {}}
{allows_unloading = true, created_by_interrupt = false, station = "aaa_second", temporary = false, wait_conditions = {}}
(nil)

ok, so adding two regular stops in order works. "aaa_second" gets added after 'zzz_first'

Code: Select all

> for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
(nil)
> train_schedule.add_record { station = 'zzz_first' }
> train_schedule.add_record { station = 'aaa_second', temporary = true }
> for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
{allows_unloading = true, created_by_interrupt = false, station = "aaa_second", temporary = true, wait_conditions = {{compare_type = "and", ticks = 300, type = "time"}}}
{allows_unloading = true, created_by_interrupt = false, station = "zzz_first", temporary = false, wait_conditions = {}}
(nil)
But a temporary stop gets added at the top of the schedule, not the bottom. The docs state Adds a record to the end of the current schedule using the provided data.

Re: [2.0.37] LuaSchedule::add_record adds temporary stops at the beginning of the schedule

Posted: Fri Feb 28, 2025 3:35 am
by hgschmie
It seems slightly more complicated. If the first stop is a temporary stop, then the new stop is put *behind* that temporary stop but *before* the first permanent stop:

Code: Select all

> for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
(nil)
train_schedule.add_record { station = "test", temporary = true }
(nil)
train_schedule.add_record { station = "test2", }
(nil)
for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
{allows_unloading = true, created_by_interrupt = false, station = "test", temporary = true, wait_conditions = {{compare_type = "and", ticks = 300, type = "time"}}}
{allows_unloading = true, created_by_interrupt = false, station = "test2", temporary = false, wait_conditions = {}}
(nil)
train_schedule.add_record { station = "test3", temporary = true }
(nil)
for i = 1, train_schedule.get_record_count() do print(serpent.line(train_schedule.get_record{ schedule_index = i })) end
{allows_unloading = true, created_by_interrupt = false, station = "test", temporary = true, wait_conditions = {{compare_type = "and", ticks = 300, type = "time"}}}
{allows_unloading = true, created_by_interrupt = false, station = "test3", temporary = true, wait_conditions = {{compare_type = "and", ticks = 300, type = "time"}}}
{allows_unloading = true, created_by_interrupt = false, station = "test2", temporary = false, wait_conditions = {}}
(nil)

Re: [2.0.37] LuaSchedule::add_record adds temporary stops at the beginning of the schedule

Posted: Fri Feb 28, 2025 3:49 am
by robot256
As Rseding has said, the new interface replicates the user interface almost exactly. This sounds like it's replicating the intentionally broken insertion of temporary stops as described here: viewtopic.php?t=118266

2.0.38 should have the ability to pass an index into add_record() that will hopefully bypass the broken logic.

Re: [2.0.37] LuaSchedule::add_record adds temporary stops at the beginning of the schedule

Posted: Fri Feb 28, 2025 1:32 pm
by Rseding91
Semi-duplicate of 127180

Re: [2.0.37] LuaSchedule::add_record adds temporary stops at the beginning of the schedule

Posted: Fri Feb 28, 2025 3:37 pm
by robot256
Rseding91 wrote: Fri Feb 28, 2025 1:32 pm Semi-duplicate of 127180
Any chance of getting more detail on viewtopic.php?t=118266 ? I still don't see how it was a useful change. With the new API we can make a mod to fix it, which is great, but that doesn't explain the regression in usability.