Switch Button by GalactusX31 updated for 1.0


This mod adds on/off switch button for sending a single circuit network signal. Mod settings allow to either toggle On/Off state by left-click and access inventory via hotkey, or to work like a regular constant combinator.

Content
3 years ago
1.0 - 1.1
8.44K
Circuit network

g [fixed] Add default signal

mk-fg β˜†
3 years ago
(updated 3 years ago)

Hey, thanks for reviving a nice mod!

Maybe these buttons should have some default signal set on them when they are placed?
E.g. something simple like signal-check would do.

This is so that in most cases when you build a circuit, you won't need to bother with setting it on each button or remember a hotkey and just use the default.

Also, it makes for a nicer "new user" experience, as when you install the mod and build first button, then click on it, nothing happens.
With default signal, it will flip nicely as expected, and emit an appropriate check-mark signal, which ofc can be changed if one has multiple buttons connected to the same network.

3 years ago

You can une bluprint or function copy/past (shift clic right/left)
Good argument for new player, i'm thinking about this anyway but my mastery of api factorio is limited

mk-fg β˜†
3 years ago

No worries, here is a link to 0.1.10 version with this change and couple other fixes that I've noticed to be needed there:
https://e.var.nz/Switch_Button-1_0_0.1.10.zip

Specific fixes that I've made there, in diff format are here:
https://gist.github.com/mk-fg/acf2f31741d72eb0e9c2394ea3e5a7aa

To comment on patches from last link above briefly:

  • 0002-Fix-using-mod-local-variable-as-it-will-cause-mp-des.patch

    Issue there is that "local" is not synced between players in mp game, only stuff in "global" is, so if player-1 joins game, changes that local, then player-2 joins later, their game logic state is desynced - things will happen in player-1 game differently than for player-2. Easy fix there is to just use proper globals for that.

  • 0003-Add-default-switchbutton-signal-signal-check-a-check.patch - actual change adding default signal.

  • 0004-Fix-copy-pasting-settings-now-copies-signal-and-enab.patch - fix for copying state via shift-RMB/shift-LMB.

    Now signal and enabled state will be copied properly from the source button to destination one.

  • 0005-Add-entity-filters-to-event-handling-handle-script-r.patch

    Added handling for script_raised_built/revive events, which other mods can use for also creating this button (e.g. creative-mode mod).
    And added event filters, so that factorio won't be running these hooks for anything but switchbutton entities, for better performance.

Feel free to use any or all of them separately. Linked mod zip file has all of them applied in that order.

mk-fg β˜†
3 years ago

Oh, also, wrt signal - used Checkmark=1 signal, which seem to be appropriate for such button.
It still won't enable unless connected with wire, which is how default factorio combinators work and probably isn't worth "fixing" (can be done via +1 invisible always-connected entity), but otherwise should be nicer for new users and to just place and use it these with default setting out-of-the-box manually.

3 years ago

actualy you patch fix little bug and add major ^^ http://prntscr.com/uc7wu7 and i just try build buton & clic on

mk-fg β˜†
3 years ago

Oh, right, sorry, forgot that adding on_init won't make it run for old saves, even if it wasn't there before.

I think you just need to add this one line at the bottom of the script:
script.on_configuration_changed(function() global.keybind_state = global.keybind_state or {} end)
(to do same thing as on_init but for existing saves)

It's for the first patch which moves "local keybindused" to globals.

mk-fg β˜†
3 years ago

Thanks.
Guess I'll also upload release with a proper in-game changelog (e.g. https://mods.factorio.com/mod/Moon_Logic/changelog ), so that it'll be easily visible on the mods screen when people install/update the mod.
Otherwise it's quite a simple mod, so there shouldn't be much need to tweak anything else, really.

3 years ago

_< you add an other bug if you copy switch per bp switch signal copyed but is change on build to you default signal

mk-fg β˜†
3 years ago
(updated 3 years ago)

Ah true, I just added always setting that to same on_built handler that is also used for on_robot_built_entity hook, hence it overrides whatever is in blueprint.
Will add an extra check for if signal is already set there and bundle with changelog mentioned above, I guess.

mk-fg β˜†
3 years ago

Fixed the last issue in 0.1.12.

Also wrt blueprints, found that switch was ignored if "Show signal in ALT-info mode" option was unchecked, as entities.lua was setting switchbutton.flags = {'hide-alt-info'}, removing all other flags from there, which should be {'placeable-neutral', 'player-creation', 'hide-alt-info'}.

Did update a bunch of english locale strings too, which seemed to be worded rather strangely and confusingly to me.
I'm not a native english speaker either though, and tend to be a bit dyslexic, so not entirely sure if resulting strings are great either, but hopefully at least an improvement :)

Moved changelog to changelog.txt from mod description, and added basic mod options/keybinds info there, so that it'd be less empty.

mk-fg β˜†
3 years ago
(updated 3 years ago)

Oh, also, as I use git for change-tracking, pushed the mod into this repo on github:
https://github.com/mk-fg/games/tree/master/factorio/Switch_Button-1_0
So you can easily lookup commits there to see any future changes made.
(did commit initial version as-is, without history from GalactusX31 repo or patches in the gist above, for simplicity)

New response