Switch Button updated for 2.0

by m44v

This mod adds 2 buttons that can be toggled with a mouse-click: A switch button that works like a constant combinator and a push button that outputs single-tick circuit network signals.

Utilities
5 months ago
2.0
2.11K
Circuit network

i Custom length pulse

9 months ago

Could the pushbutton version have a field to set how long the pulse will be? Where clicking it again just resets the timer. (Its quite annoying having a pulse lengthener combinator in most places I use it)

8 months ago
(updated 8 months ago)

Is 4 combinators that annoying? You gotta pump those numbers up :P

I don't know, seems like a very niche use case and I don't know how to mod the UI for add such settings to the button, they are constant combinators under the hood.

8 months ago

Personally I never need to use the pushbutton by itself, almost always the thing it interacts with (eg. capture turret, inserter, belt, etc) needs a specific length t
ime

You could always add a virtual signal, that when set is the pulse duration?

5 months ago

Hi!
In one of the latest versions, a parameter was added to the combinator, which allows you to specify the number of ticks after which it will turn off itself. Can you add this parameter to the mod?

https://lua-api.factorio.com/latest/prototypes/ConstantCombinatorPrototype.html#pulse_duration

5 months ago

More accurately, the question would sound like this: is it possible to attach a condition to a mouse click event so that the "toggle-entity" parameter is triggered?

5 months ago

What do you mean by "attach a condition"?

5 months ago

Now that you can set the auto-off time of the combinator, is it possible to make a setting that will change the behavior of the mouse click on the push button?
As I understand it, this is somehow related to "toggle entity".

5 months ago

The new .pulse_duration api doesn't help with this feature request, getting a pulse of an arbitrary number of ticks was never the issue.

The problem I have is making an UI for the user to set the custom duration, it can't be a mod setting and using a virtual signal is a bit of a hack.

There's also the maintainability of the mod, adding features that I don't personally use makes maintaining it more difficult..

a month ago

Hello!
I have the same question, almost the same.
Now the button gives a signal of 1 tick, is it possible to add a mod setting where this duration can be specified manually?
For example, the user specifies 60 ticks, and then when clicking on the button, the signal will be given with a duration of 60 ticks (1 second)?

The question arose because the signal often does not work, that is, the entity waiting for the signal input does not read it in 1 tick - perhaps because of the large number of mods, perhaps because of the large base, I don’t know for sure, but it does not have time to read it.

a month ago
(updated a month ago)

I'm not exactly sure I did it correctly (I'm not a modder), but it works and is what I needed.

local function onTick()

    local tick_count = settings.startup["tick_count"].value
    for _, control in pairs(storage.deactivating_buttons) do
        if control.valid then
            control.enabled = false
        end
    end
    storage.deactivating_buttons = {}

    for i, control in pairs(storage.activating_buttons) do
        if control.valid then
            control.enabled = true
            if control.entity.name == "bigswitchbutton2" then
                storage.deactivating_buttons[i] = control
            end
        end
    end
    if (game.tick % tick_count) == 0 then
        storage.activating_buttons = {}

        if next(storage.deactivating_buttons) == nil then
            -- all buttons done, unregister the handler
            script.on_event(defines.events.on_tick, nil)
        end
    end
end

And accordingly, the settings:

    {
        type = "int-setting",
        name = "tick_count",
        setting_type = "startup",
        default_value = 60,
        minimum_value = 1,
        maximum_value = 99999,
        order = "z",
    },

Now the button gives a signal lasting 60 ticks (sometimes for some reason shorter than 60 ticks), but this is enough to not miss the signal.

New response