Page 1 of 1

How to set train limit from script?

Posted: Tue Aug 24, 2021 1:34 pm
by utoxin
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" }
        }
)

Re: How to set train limit from script?

Posted: Tue Aug 24, 2021 1:45 pm
by boskid
Most likely what you want is not the control behavior, but you want to write directly to the LuaEntity::trains_limit. Control behavior is just a way to configure an automatic overwrite of train stop's limit value every tick taking a value from circuit network.

Re: How to set train limit from script?

Posted: Tue Aug 24, 2021 1:50 pm
by utoxin
Hmm, okay, that makes some sense. Testing that now.... YES.

Thank you. I'd tried to spot a setting in there, but somehow missed that one.