Switch a switch with a simple clic

This is the place to request new mods or give ideas about what could be done.
Post Reply
Friendch
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Jul 24, 2021 6:19 am
Contact:

Switch a switch with a simple clic

Post by Friendch »

Hello there !
I would like to make a mod, or a mod request :

I'd like to be able to switch a switch without the need to go inside it's window, by Alt+clicking on it, or middle clicking on it for exemple, or even simply clic on it bypassing the window if it has no other use.

The Discord's quick questions channel, after answering that its indeed not possible in vanilla game, kindly gave me all documentation needed about mod making when I said it would be a nice addition, and that I'd even love to try myself ; But after looking at it yesterday afternoon, I have to admit that I'm totally overwhelmed... ^^

Thanks.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Switch a switch with a simple clic

Post by PFQNiet »

The power switch's GUI does have other uses, notably when using it with the circuit network, so I wouldn't advise bypassing it entirely.

However, you can add a custom-input to work with it.

data.lua:

Code: Select all

data:extend{
  {
    type = "custom-input",
    name = "toggle-power-switch",
    key_sequence = "ALT + mouse-button-1",
    action = "lua",
    consuming = "game-only"
  }
}
Give an appropriate translation in locale/en/strings.cfg:

Code: Select all

[controls]
toggle-power-switch=Toggle power switch
And finally handle the event in control.lua:

Code: Select all

script.on_event("toggle-power-switch", function(event)
  local player = game.players[event.player_index]
  local entity = player.selected
  if entity and entity.valid and entity.type == "power-switch" then
    entity.power_switch_state = not entity.power_switch_state
  end
end)
And that should do it!

Friendch
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Jul 24, 2021 6:19 am
Contact:

Re: Switch a switch with a simple clic

Post by Friendch »

Thanks for the quick answer !

Ah yes circuits, and I'm starting to think about it, will try to learn, so indeed lets prefer to keep the window ^^

So, I make it in a mod structure right ? I looked inside another mod to figure, made the files and folder, zip it, the game doesn't see it.
Is it ok if I did all that from windows alone ? I used notepad and renamed .txt as .lua. Made sure I have right file names and folder positions.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Switch a switch with a simple clic

Post by PFQNiet »


Friendch
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Jul 24, 2021 6:19 am
Contact:

Re: Switch a switch with a simple clic

Post by Friendch »

PFQNiet, it works, it works ! ^^
Still had to trial and error a bit, I'm ashamed to say that the lamest of those error was because I kept all the "CODE: SELECT ALL" in the files :oops: lmao
But damn it works ! I feel like a modder now 8-) After all, I almost made all the work ! :lol:

Thanks much ! Big thanks ! It's uber practical, so smooth :D

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Switch a switch with a simple clic

Post by PFQNiet »

Welcome to the realm of modding :D Make sure you understand what the code is doing and I hope to see your creations in future!

Post Reply

Return to “Ideas and Requests For Mods”