Switch Button


This mod adds a switch button with capacity for a single logical signal, it also can work in reverse mode, that means, when player do left-mouse click, it switch his state ON/OFF, and when a configured keybind is presed, it open his gui inventory.

Utilities
6 years ago
0.16
12

g activate by clicking instead of "f" key

6 years ago
(updated 6 years ago)

im not sure if its possible, but there's the event on_gui_click that fires when you click the entity.
i couldn't find out how to do event.element.destroy(), but another possibility would be to destroy the entity and create it new.
of course the first time you click it, it would simply open the gui so you can set it up.
thanks for the mod and good luck

6 years ago

I'm working on it, if I get it, I'll add it in the next version of the mod.

6 years ago

I have achieved it, it works correctly, I hope you enjoy it :)

6 years ago
(updated 6 years ago)

thats really cool, to be honest i was not entirely sure if it was possible :)

6 years ago
(updated 6 years ago)

one more suggestion though:
when i first used this mod i was totally unaware of the "f" key, so opening the gui when first clicking the button would help newbies, while also feeling more convenient
(btw, do you think it is possible to hide the signal overlay that's blended in with the "alt" key?)

6 years ago
  1. I suppose that when someone installs a mod, usually the information of the mod is read, anyway I have put the page link of the forum where the operation and configuration is explained.
  2. I think it is possible to hide the icon shown when pressing ATL-key overlay .. I should investigate more, and if possible, I will add that option to the mod in a new version of it.
6 years ago

Unfortunately I don't think it's possible to show the icon when using the ALT overlay. That handling is built-in into Factorio and is not moddable.

I had a thought for a while that maybe it was possible with a workaround to add an entity to the map that would show the graphic for the configured signal if the player had ALT-key pressed (which you can check by using this API: player.game_view_settings.show_entity_info ) but it wouldn't be possible to toggle this individually for each player (Always keep multiplayer in mind!) and I don't think it's possible to put an entity on the map that can take the view of any signal in that way.

6 years ago

yes, i found it! there is a way to "hide" the icon that appears when using the ALT key for overlay icons ... but dont know if it would be useful to add this function to the mod, because it dont add gameplay to it, and also, hinders being able to see what logical signal it has configured inside.

you can see the function right here: http://lua-api.factorio.com/latest/LuaEntityPrototype.html#LuaEntityPrototype.has_flag

6 years ago

i would say every player has the "alt-key"-overlay always active, so you never see what the button's switch state currently is.

6 years ago

i like the switch. it looks really nice, but the overlay hides the most interesting part of the switch: the ON/OFF status.

while building some circuitry, it might be useful to have the overlay, but when it's finished, we should be able to hide the overlay so that for operating the factory, there is only a row of switches without overlays (similar to "historic" computers which were operated with a row of switches and nixies for display of results :-)
thus please add an option to have/hide the overlays.

i also have another problem with the current options: I'm also using the pushbutton mod, and both mods should not have quite different behavior how to operate the buttons and switches. for pushbuttons, a click opens the interface, a hotkey (F) pushes the button, and E opens the normal crafting window. that mod also has a second functionality: applied to constant combinators, the hotkey (F) toggles them on/off, just like switchbuttons without the nice graphics. now i would like to have the same for the switchbutton: pushing F should toggle it on/off but i also would like to be able simply clicking on the switch button to toggle it on/off.

now the problem: to allow clicking the button to toggle it, i had to reverse the functions in the mod settings. this properly allows me to click for toggling, but all the rest is messed up and just the reverse of the pushbutton mod: E is now the hotkey to toggle it on/off, and F opens the gui.
i even tried to set the hotkey to E, but that causes a cycle with four states: open gui with switch on, close gui and toggle to off, open gui with switch off, close gui and toggle to on. i also tried to clear the hotkey, but that disables the gui completely.

my wishes for both mods: activate function (pulse for pushbutton, toggle for switchbutton) with a hotkey (that is selectable, like it is now), and open the gui by pushing E (maybe have a second selectable hotkey instead of the constant E to open the gui; i have seen some mods with hotkeys to open their guis). and separately from the E key and the hotkey, have an option whether clicking the item should open the gui or activate its function. (worded differently, i want two additions/changes: a pushbutton that can be activated for a pulse by clicking on it, and that hotkey and E key are not exchanged when selecting to alter the gui behavior of switchbuttons).

since those changes have to be done on both mods, and both mods have very similar functionality (one pulses, the other toggles, but both basically are constant combinators with new graphics and a new hotkey and a gui that optionally is no longer opened by clicking) it would be nice if the two push/switch-buttons were available in one single mod. (and/or please talk with the other author and make handling them more similar to each other)

6 years ago

Thanks for your review and opinions, i will talk wiht the other mod mate, and we will see if this is possible :) ... also, slowly learning how to add more options and features

6 years ago

i'm not sure if im okay with the e key toggling the switch, but i'm really glad you added an option to hide the alt-overlay, thanks!!

6 years ago

Thanks .. I dont know why the switch button turn his state to ON-OFF when you press the key "E" ... it also togle his state when you press the key "B" ... maybe its a factorio bug, or i miss anything important o_O

6 years ago
(updated 6 years ago)

that's due to the event script.on_event(defines.events.on_gui_opened
when you click the entity, player.opened will not be nil and have player.opened.name == "switchbutton", you could check for that

6 years ago
(updated 6 years ago)

instead of the "if distance < 15 or player.character == nil" part, you could use "if player.character == nil or player.character.can_reach_entity(entity)"... that way it would include reach distance bonuses
the on_gui_opened function already works with reach bonuses

6 years ago

I recently modified the code and added this feature, thanks for the help, I hope it works correctly now

New response