This request may have finally been implemented!!!!!
Hidden in the docs for 2.0.36 is a new class, LuaSchedule, which includes accessor functions like add_interrupt.
[2.0] Be able to read/write interrupts for trains/space platforms
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Yeah, but with type mismatch.. =(robot256 wrote: Wed Feb 26, 2025 3:19 pm This request may have finally been implemented!!!!!
Hidden in the docs for 2.0.36 is a new class, LuaSchedule, which includes accessor functions like add_interrupt.
Fro example: LuaSchedule.get_record(index) expect 'table' not index. Same as LuaSchedule.remove_record(index). What?!
And so on..
For now you must to save list of interupts localy, then update list of schedule records and after add interrupts back.
Something like that:
Code: Select all
local schedule = train.get_schedule()
-- save old interrupts
local number_of_interupts = schedule.interrupt_count
local old_interrupts = {}
if number_of_interupts > 0 then
for interruptIndex = 1, number_of_interupts, 1 do
old_interrupts[interruptIndex] = schedule.get_interrupt(interruptIndex)
end
end
-- Set new schedule
train.schedule = newSchedule
-- return iterrupts back
schedule = train.get_schedule()
for interruptIndex = 1, #old_interrupts, 1 do
schedule.add_interrupt(old_interrupts[interruptIndex])
end
Re: [2.0] Be able to read/write interrupts for trains/space platforms
What? Did you read the docs? get_record and remove_record require https://lua-api.factorio.com/latest/con ... ition.html which you say if the record is part or a "normal" record or a record inside an interrupt.ZlovreD wrote: Sun Mar 02, 2025 12:05 pm Yeah, but with type mismatch.. =(
Fro example: LuaSchedule.get_record(index) expect 'table' not index. Same as LuaSchedule.remove_record(index). What?!
And so on..
Again, what? You don't need to use .schedule read/write at all anymore. You use purely LuaSchedule to modify directly any part you want.ZlovreD wrote: Sun Mar 02, 2025 12:05 pm For now you must to save list of interupts localy, then update list of schedule records and after add interrupts back.
If you want to get ahold of me I'm almost always on Discord.
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Oh.. get_record(index) - In my world "Index" means integer.Rseding91 wrote: Sun Mar 02, 2025 12:27 pm What? Did you read the docs? get_record and remove_record require https://lua-api.factorio.com/latest/con ... ition.html which you say if the record is part or a "normal" record or a record inside an interrupt.
So i need to write .get_record({schedule_index: 1}) ?
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Because each interrupt can have multiple schedule records attached to it, you have to specify both which interrupt (or none) and which stop index within that sequence.
It might make more sense if the "record_index" type were called "record_location" or "record_identifier".
It might make more sense if the "record_index" type were called "record_location" or "record_identifier".
My mods: Multiple Unit Train Control, Smart Artillery Wagons
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk
Maintainer of Vehicle Wagon 2, Cargo Ships, Honk