[2.0] Be able to read/write interrupts for trains/space platforms

robot256
Smart Inserter
Smart Inserter
Posts: 1083
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0] Be able to read/write interrupts for trains/space platforms

Post 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.
User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 132
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

Re: [2.0] Be able to read/write interrupts for trains/space platforms

Post 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
Rseding91
Factorio Staff
Factorio Staff
Posts: 15039
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [2.0] Be able to read/write interrupts for trains/space platforms

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
ZlovreD
Fast Inserter
Fast Inserter
Posts: 132
Joined: Thu Apr 06, 2017 1:07 pm
Contact:

Re: [2.0] Be able to read/write interrupts for trains/space platforms

Post by ZlovreD »

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.
Oh.. get_record(index) - In my world "Index" means integer.
So i need to write .get_record({schedule_index: 1}) ?
robot256
Smart Inserter
Smart Inserter
Posts: 1083
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: [2.0] Be able to read/write interrupts for trains/space platforms

Post 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".
Post Reply

Return to “Implemented mod requests”