How to set train limit from script?
Posted: Tue Aug 24, 2021 1:34 pm
I'm trying to write a mod that can configure the train limits of a train stop as it is placed. So far, I've got the code that hooks into the right events, and gets the control behavior of the stop, but I can't for the life of me figure out how to actually configure it. I've dug around and looked at other mod code that interacts with this, especially the code for ConcurrentTrainRestriction, but none of it seems to work for me. I can't even get it to check the box. Here's my event handler.
Code: Select all
local event = require("__flib__.event")
event.register(
{ defines.events.on_built_entity },
function(event)
local behavior = event.created_entity.get_or_create_control_behavior()
if behavior then
behavior.enable_disable = true
behavior.set_trains_limit = true
behavior.read_trains_count = true
behavior.trains_limit_signal = {["name"] = "locomotive", ["type"] = "item"}
end
end,
{
{ filter="type", type="train-stop" }
}
)