LuaSchedule API

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
hgschmie
Fast Inserter
Fast Inserter
Posts: 113
Joined: Tue Feb 06, 2024 5:18 am
Contact:

LuaSchedule API

Post 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()
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 390
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: LuaSchedule API

Post 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.
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai
Rseding91
Factorio Staff
Factorio Staff
Posts: 15225
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaSchedule API

Post by Rseding91 »

See 127180
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding interface requests”