Page 1 of 1

Full LuaSchedule support for interrupts

Posted: Sat May 10, 2025 5:43 pm
by Gweneph
I love the LuaSchedule interface for modifying schedules.

However, when I want to modify the schedule of an interrupt I mostly have to fall back on the get table, modify table, set table method.

I have two proposals for adding full support for modifying the API. The first follows the examples set by drag_redcord, get_record, etc. to add an optional interrupt index parameter. Here's the changes to the API in bold:

add_wait_condition(record_index, condition_index, type, interrupt_index?)
remove_wait_condition(record_index, condition_index, interrupt_index?)
set_wait_condition_mode(record_index, condition_index, mode, interrupt_index?)
change_wait_condition(record_index, condition_index, wait_condition, interrupt_index?)
add_record(data, interrupt_index?)
remove_record(index, interrupt_index?)
copy_record(source_schedule, source_index, destination_index, source_interrupt_index?, destination_interrupt_index?)
add_interrupt(interrupt)
remove_interrupt(index)
activate_interrupt(index)
change_interrupt(index, interrupt)
rename_interrupt(old_name, new_name)
go_to_station(schedule_index)
set_stopped(stopped)
set_allow_unloading(index, allow)
drag_record(from, to, interrupt_index?)
drag_interrupt(from, to)
drag_wait_condition(index, from, to, interrupt_index?)
get_record(index, interrupt_index?)
get_records(interrupt_index?)
set_records(records, interrupt_index?)
clear_records(interrupt_index?)
get_interrupt(index)
get_interrupts()
set_interrupts(interrupts)
clear_interrupts()
get_wait_condition(schedule_index, condition_index, interrupt_index?)
get_wait_conditions(schedule_index, interrupt_index?)
get_wait_condition_count(index, interrupt_index?)
get_record_count(interrupt_index?)
owner
interrupt_count
current
tick_of_last_schedule_change
tick_of_last_activity
ticks_in_station
group
valid
object_name
The second proposal would be to have get_interrupt return a stripped down LuaSchedule where many members wouldn't apply. Here's the API where the struck through members wouldn't apply to the interrupt schedules:
add_wait_condition(record_index, condition_index, type)
remove_wait_condition(record_index, condition_index)
set_wait_condition_mode(record_index, condition_index, mode)
change_wait_condition(record_index, condition_index, wait_condition)
add_record(data)
remove_record(index)
copy_record(source_schedule, source_index, destination_index)
add_interrupt(interrupt)
remove_interrupt(index)
activate_interrupt(index)
change_interrupt(index, interrupt)
rename_interrupt(old_name, new_name)
go_to_station(schedule_index)
set_stopped(stopped)

set_allow_unloading(index, allow)
drag_record(from, to)
drag_interrupt(from, to)
drag_wait_condition(index, from, to)
get_record(index)
get_records()
set_records(records)
clear_records()
get_interrupt(index)
get_interrupts()
set_interrupts(interrupts)
clear_interrupts()

get_wait_condition(schedule_index, condition_index)
get_wait_conditions(schedule_index)
get_wait_condition_count(index)
get_record_count()
owner
interrupt_count
current
tick_of_last_schedule_change
tick_of_last_activity
ticks_in_station
group

valid
object_name
This immediately suggests to me a refactoring LusSchedule to split it into LuaScheduleStatus which gets all of those crossed out members as well as get_schedule. Of course that would be a breaking change, so :(.

Either of these changes could be further enhanced by allowing the wait condition calls to refer to the interrupt triggers when schedule_index is 0 or nil.

Re: Full LuaSchedule support for interrupts

Posted: Sun May 11, 2025 12:37 pm
by Rseding91
I'm confused, all of the existing methods already support interacting with interrupts.

An example: add_record -> https://lua-api.factorio.com/latest/cla ... add_record specifically the https://lua-api.factorio.com/latest/con ... dData.html 'index' value is of type https://lua-api.factorio.com/latest/con ... ition.html which is "either a standard record, or an interrupt" so you can already add_record straight to an interrupt.

Re: Full LuaSchedule support for interrupts

Posted: Mon May 12, 2025 5:20 pm
by Gweneph
Whoops! I didn't check on ScheduleRecordPosition. In that case, the majority of my request is satisfied. Thanks!

I think the only thing left is copy_record accepts uint for it's indexes rather than ScheduleRecordPositions. Could that be modified to accept ScheduleRecordPosition instead?

Also, it looks like the only way to get/modify inside_interrupt is through the table get modify set idiom.

Re: Full LuaSchedule support for interrupts

Posted: Mon May 12, 2025 5:57 pm
by Rseding91
"inside_interrupt" is mostly an internal state that mods should theoretically have no reason to modify.

Re: Full LuaSchedule support for interrupts

Posted: Mon May 12, 2025 9:24 pm
by Gweneph
Sorry, I'm referring to the inside_interrupt that's part of a ScheduleInterrupt.It seems to track the check box "Allow interrupting other interrupts":

As far as I can tell this can be modified through getting the ScheduleInterrupt table, modifying it, and then setting it back, but it would be nice to have a getter/setter in LuaSchedule.

Re: Full LuaSchedule support for interrupts

Posted: Mon May 12, 2025 9:34 pm
by Rseding91
Ah right, the Lua name for it is just slightly confusing. There doesn't currently appear to be a way to change that without removing and replacing an interrupt.

Re: Full LuaSchedule support for interrupts

Posted: Mon May 19, 2025 11:14 pm
by Rseding91
I've added LuaSchedule::get_inside_interrupt()/set_inside_interrupt() for the next release.