How to set train limit from script?

Place to get help with not working mods / modding interface.
Post Reply
utoxin
Inserter
Inserter
Posts: 35
Joined: Tue Apr 25, 2017 4:51 pm
Contact:

How to set train limit from script?

Post 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" }
        }
)

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: How to set train limit from script?

Post 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.

utoxin
Inserter
Inserter
Posts: 35
Joined: Tue Apr 25, 2017 4:51 pm
Contact:

Re: How to set train limit from script?

Post 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.

Post Reply

Return to “Modding help”