Valves


Adds three seperate animated valves for pipes: overflow, top-up and one-way/check valves. Inspired by Flow Control and Advanced Fluid Handling. The thresholds can be configured using shortcuts. Uses valve functionality provided by Factorio.

Utilities
2 months ago
2.0
50.4K
Logistics Fluids

g [Command Available] Migration from Configurable Vavles

10 months ago

We first migrated from py 1.1 to 2.0 using the configurable valves mod. Would it be possible to have a migration that allows us to switch to this, since we are not using any other configuration of valves?

10 months ago

Hello! It is possible and on my TODO list, I just haven't had time for it before. I hoped it would be longer until someone would need it . I'll see if I can add it this week. It will likely be a command like /migrate-from-configurable-valves while you have both mods active.

10 months ago

perfect, thanks a ton!

10 months ago
(updated 10 months ago)

I've decided not to add it. There's no reliable way to migrate from one way to the other in a way that includes items, ghosts, blueprints, etc.

Here is a command you can use though. Use at own risk, and keep a backup save! It should print out the locations of valves that didn't fit any of the three new valve configurations.

/c

local function deduce_type(behaviour)
    local circuit_condition = behaviour.circuit_condition
    local first = circuit_condition.first_signal and circuit_condition.first_signal.name
    local second = circuit_condition.second_signal and circuit_condition.second_signal.name
    if first == "signal-I" and not second and circuit_condition.comparator == ">" then
        return "overflow"
    elseif first == "signal-O" and not second and circuit_condition.comparator == "<" then
        return "top_up"
    elseif first == "signal-I" and second == "signal-O" and circuit_condition.comparator == ">" then
        return "one_way"
    end
end

for _, surface in pairs(game.surfaces) do
    for _, configurable_valve in pairs(surface.find_entities_filtered{name="configurable-valve"}) do
        local configurable_behaviour = configurable_valve.get_or_create_control_behavior()
        local valve_type = deduce_type(configurable_behaviour)

        if not valve_type then
             game.print("Unknown valve configuration not migrated at: "..valve.gps_tag)
             continue
        end

        local threshold
        if valve_type == "overflow" or valve_type == "top_up" then
            threshold = configurable_behaviour.circuit_condition.constant
            if not threshold then threshold = valve_type == "overflow" and 80 or 50 end
        end

        local position = configurable_valve.position
        local direction = configurable_valve.direction
        local force = configurable_valve.force
        configurable_valve.destroy{ raise_destroy = true }

        local valve = surface.create_entity{
            name = valve_type and "valves-"..valve_type or "valves-overflow",
            position = position,
            direction = direction,
            force = force,
            raise_built = true,
        }
        if valve then
            local behaviour = valve.get_or_create_control_behavior()
            behaviour.circuit_condition.constant = threshold or 100
        end
        ::continue::
    end
end
10 months ago
(updated 10 months ago)

Getting an error: Unknown entity name: overflow
Changed the overflow to valves-overflow and seems to all work now?

10 months ago
(updated 10 months ago)

Oops, coding mistake. Thanks, I fixed it. Just be careful, if that triggered then there was a valve that this couldn't figure out if it should be an top-up, overflow or one-way. So it defaulted to overflow 100%. If you still have your old save you can run this command again. It should now print the location of that valve.

10 months ago

still getting some errors, ')' expected near '...'

10 months ago

Fixed. Had one to many dots. Sorry, I'm at work so coding blindly.

10 months ago

No worries, thanks a lot for responding so far!

New response