Ghost Mode

by dudditz

Toggle "Ghost-mode", making all entities you build a ghost regardless of what's in your inventory. Bascially, it holds down Shift for you. Ghost-mode can be toggled via the default key binding Shift + G or the shortcut bar.

Utilities
5 months ago
1.1
214

b Ghost mode shortcut button toggles no matter which button is clicked

6 months ago
(updated 6 months ago)

I have the Ghost Mode mod installed, with the shortcut button shown on my toolbar. I have several other mods installed as well, some of which also have a shortcut button. There seems to be a problem where the Ghost Mode button toggles on and off, no matter which shortcut button is pressed. It seems that your code is intercepting button-press messages which are intended for other mods.
I have experimented a little, and I think I have found a solution. In your 'control.lua' file, find this section of code:

script.on_event(defines.events.on_lua_shortcut,
function(event)
local player = game.get_player(event.player_index)
toggle_ghost_mode(player)
end
)

and amend it like this:

script.on_event(defines.events.on_lua_shortcut,
function(event)
if event.prototype_name == "ghost_mode_toggle_shortcut" then
local player = game.get_player(event.player_index)
toggle_ghost_mode(player)
end
end
)

This should ensure that your code only responds to button presses which were specifically intended for the Ghost Mode mod.
(Sorry about the lack of indentation - sadly, it seems that these messages don't take any notice of tabs or leading spaces.)

5 months ago

Nice catch, thanks! Fixed.