Page 1 of 1

LuaSchedule API

Posted: Thu Feb 27, 2025 7:12 am
by hgschmie
Thank you for adding this to Factorio!

A few comments:

- LuaSchedule::add_record should either return the index at which the record was inserted *or* have a parameter that allows defining where the record goes in the schedule. Currently I do

Code: Select all

schedule.add_record { ... }
local index = schedule.get_record_count() -- last index is the new record
schedule.drag_record(index, desired_index)  -- move record around
Which seems less than ideal

- add_wait_condition and change_wait_condition

Currently, add_wait_condition adds a generic "WaitConditionType" record, which then subsequently needs to be modified. So my code looks like this:

Code: Select all

schedule.add_wait_condition({ schedule_index = index }, 1, 'inactivity') -- see https://forums.factorio.com/viewtopic.php?t=127153
schedule.change_wait_condition({ schedule_index = index }, 1, { type = 'inactivity', ticks = number_of_ticks, })
(this API takes a "condition_index". Why does add_record not have a "record_index"?)

- retrieving the schedule is hard compared to the old API:

Code: Select all

local records = {}
local record_count = schedule.get_record_count()
if record_count then
    for i = 1, record_count, 1 do
        table.insert(records, schedule.get_record { schedule_index = i })
    end
end
return records
compared to "train.schedule" on the old API. Can we have a LuaSchedule::get_records()

Re: LuaSchedule API

Posted: Thu Feb 27, 2025 12:34 pm
by LuziferSenpai
hgschmie wrote: Thu Feb 27, 2025 7:12 am Thank you for adding this to Factorio!

A few comments:

- LuaSchedule::add_record should either return the index at which the record was inserted *or* have a parameter that allows defining where the record goes in the schedule. Currently I do

Code: Select all

schedule.add_record { ... }
local index = schedule.get_record_count() -- last index is the new record
schedule.drag_record(index, desired_index)  -- move record around
Which seems less than ideal

- add_wait_condition and change_wait_condition

Currently, add_wait_condition adds a generic "WaitConditionType" record, which then subsequently needs to be modified. So my code looks like this:

Code: Select all

schedule.add_wait_condition({ schedule_index = index }, 1, 'inactivity') -- see https://forums.factorio.com/viewtopic.php?t=127153
schedule.change_wait_condition({ schedule_index = index }, 1, { type = 'inactivity', ticks = number_of_ticks, })
(this API takes a "condition_index". Why does add_record not have a "record_index"?)

- retrieving the schedule is hard compared to the old API:

Code: Select all

local records = {}
local record_count = schedule.get_record_count()
if record_count then
    for i = 1, record_count, 1 do
        table.insert(records, schedule.get_record { schedule_index = i })
    end
end
return records
compared to "train.schedule" on the old API. Can we have a LuaSchedule::get_records()
get_records & record_index for add_record will get added next patch.

Re: LuaSchedule API

Posted: Fri Feb 28, 2025 1:34 pm
by Rseding91
See 127180