Full LuaSchedule support for interrupts

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Gweneph
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Thu Nov 14, 2019 11:51 pm
Contact:

Full LuaSchedule support for interrupts

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

Re: Full LuaSchedule support for interrupts

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Gweneph
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Thu Nov 14, 2019 11:51 pm
Contact:

Re: Full LuaSchedule support for interrupts

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

Re: Full LuaSchedule support for interrupts

Post by Rseding91 »

"inside_interrupt" is mostly an internal state that mods should theoretically have no reason to modify.
If you want to get ahold of me I'm almost always on Discord.
Gweneph
Long Handed Inserter
Long Handed Inserter
Posts: 57
Joined: Thu Nov 14, 2019 11:51 pm
Contact:

Re: Full LuaSchedule support for interrupts

Post 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.
Attachments
Train interrupt edit menu
Train interrupt edit menu
temp.png (31.79 KiB) Viewed 79 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 15578
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Full LuaSchedule support for interrupts

Post 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.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding interface requests”