Page 2 of 2
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Posted: Wed Feb 26, 2025 3:19 pm
by robot256
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.
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Posted: Sun Mar 02, 2025 12:05 pm
by ZlovreD
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.
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..
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
And one more thing - there are two similar types: TrainSchedule and LuaSchedule
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Posted: Sun Mar 02, 2025 12:27 pm
by Rseding91
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..
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
For now you must to save list of interupts localy, then update list of schedule records and after add interrupts back.
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.
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Posted: Sun Mar 02, 2025 6:36 pm
by ZlovreD
Oh.. get_record(index) - In my world "Index" means integer.
So i need to write .get_record({schedule_index: 1}) ?
Re: [2.0] Be able to read/write interrupts for trains/space platforms
Posted: Sun Mar 02, 2025 11:56 pm
by robot256
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".